Skip site navigation (1) Skip section navigation (2)

Re: referencing to "computed columns" in where clause

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: referencing to "computed columns" in where clause
Date: 2008-01-29 17:49:50
Message-ID: 20080129184950.19999212@webthatworks.it (view raw or flat)
Thread:
Lists: pgsql-general
On Tue, 29 Jan 2008 17:17:39 +0000
Sam Mason <sam(at)samason(dot)me(dot)uk> wrote:

> On Tue, Jan 29, 2008 at 06:04:48PM +0100, Ivan Sergio Borgonovo
> wrote:
> > select
> >   case
> >     when (a>3) then a*b
> >     when (a<3) then a+b
> >   end as pippo
> > where pippo<12;
> 
> I've tended to do:
> 
>   SELECT *
>   FROM (
>     SELECT "complicated expression" AS pippo) x
>   WHERE pippo  < 12;

It risk to be much harder to rewrite for dumber DB than repeating the
"complicated expression".

Does it come with some extra cost/improvement in term of performance
compared to:
- repeating the code of "complicated expression"
- put it in a function with the proper "attributes" (I'd say
IMMUTABLE in the above case)

I've some argument for all cases but it should depend on the
implementation.

thanks

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it


In response to

Responses

pgsql-general by date

Next:From: Richard Broersma JrDate: 2008-01-29 17:52:38
Subject: Re: referencing to "computed columns" in where clause
Previous:From: Sam MasonDate: 2008-01-29 17:17:39
Subject: Re: referencing to "computed columns" in where clause

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group