Re: [HACKERS] calculated fields are not seen in the WHERE clause

From: "Henshall, Stuart - Design & Print" <SHenshall(at)westcountry-design-print(dot)co(dot)uk>
To: 'Yaroslav Dmitriev' <yar(at)warlock(dot)ru>, "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: [HACKERS] calculated fields are not seen in the WHERE clause
Date: 2002-10-30 13:04:42
Message-ID: E2870D8CE1CCD311BAF50008C71EDE8E0506DC7E@MAIL_EXCHANGE
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Browse pgsql-general by date

  From Date Subject
Next Message Diogo Biazus 2002-10-30 13:37:19 Re: Database Design tool
Previous Message Graeme Hinchliffe 2002-10-30 11:59:41 Re: DAFS?