Re: [HACKERS] calculated fields are not seen in the WHERE clause - Mailing list pgsql-general

From Henshall, Stuart - Design & Print
Subject Re: [HACKERS] calculated fields are not seen in the WHERE clause
Date
Msg-id E2870D8CE1CCD311BAF50008C71EDE8E0506DC7E@MAIL_EXCHANGE
Whole thread Raw
List pgsql-general

Yaroslav Dmitriev wrote:
> Hello,
>
> OK
> select 1 as ccc where 1=1
>
> ERROR
> select 1 as ccc where ccc=1
> PostgreSQL said: ERROR: Attribute 'ccc' not found
>
> Is there any way to set conditions on calculated fields values?
>
> Best regards,
> Yar
>
No, the only way to do this is ot repeat the calculation.
If you wonder why here are a few reasons:
Aggregate functions - How can a where condition be based on something like MAX() or SUM()
Side effects of functions. Say for instance a have a function to delete things,
I might use the SELECT del_func(...) FROM tbl WHERE tm<'10/20/02';
If it didn't restrict first everything would get deleted.
Efficiency. If it had to base where conditions on calculated fields it would have to retreive all rows
that might fit, instead of say using an index to select the one row you really need.
hth,
- Stuart

pgsql-general by date:

Previous
From: derek@spencerogne.com (Derek Spencer)
Date:
Subject: maximum number of triggers on a table?
Next
From: Viacheslav N Tararin
Date:
Subject: Database Design tool