pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreak@officenet.no>
To: pgsql-sql@postgresql.org
Subject: Re: RE: Referencing named attribute in where clause doesn't work with7.1.2?
Date: Wed, 08 Aug 2001 16:41:06 +0200
Message-ID: <3B714F82.D8912EEE@officenet.no> (raw)
References: <08CD1781F85AD4118E0800A0C9B8580B094B8D@NEZU>

Jeff Eckermann wrote:
> 
> The WHERE clause is evaluated before your SELECT list is determined, so the
> aliased value cannot be used.
> You can put further NOT NULL tests into the subqueries to make sure that
> null values are not returned.
> Question: why not just join the tables explicitly?

:-) Because I'm not too familiar with joins.

> The more usual SQL
> approach would be something like:
> 
> SELECT article.title_text_key, on_text.text_value AS title_text_value
> FROM article INNER JOIN (on_text INNER JOIN (code INNER JOIN code_group ON
> code.code_group_id = code.id) ON on_text.lang_id = code.id) ON
> article.title_text_key = on_text.text_key
> WHERE on_text.text_value IS NOT NULL;
> 
> or whatever other tests you want.  In this case, you can easily reference
> the fields by name.

The problem with the query above is that it doesn't include my
"code.code_key='lang.NO'" test.

I rephrased the query as follows:

SELECT article.title_text_key, on_text.text_value AS title_text_value
FROM article INNER JOIN (on_text INNER JOIN (code INNER JOIN code_group
ON
code.code_group_id = code_group.id) ON on_text.lang_id = code.id AND
code_group.description = 'lang' AND code.code_key = 'lang.NO') ON
article.title_text_key = on_text.text_key
WHERE on_text.text_value IS NOT NULL;

And now it works!

Thank you for helping me out.

--
Andreas Joseph Krogh <andreak@officenet.no>



view thread (7+ messages)  latest in thread

Message-ID: <3B714F82.D8912EEE@officenet.no>
Permalink:  ../3B714F82.D8912EEE@officenet.no/
Also on:    postgresql.org/message-id/3B714F82.D8912EEE@officenet.no

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: andreak@officenet.no
  Subject: Re: RE: Referencing named attribute in where clause doesn't work with7.1.2?
  In-Reply-To: <3B714F82.D8912EEE@officenet.no>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox