Re: Need help optimizing this query

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Michael Glaesemann <grzm(at)seespotcode(dot)net>
Cc: "Pat Maddox" <pergesu(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Need help optimizing this query
Date: 2007-07-18 21:14:24
Message-ID: 9CDB3C3E-0C9F-4502-A3D3-A5DD486C4F7C@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Jul 18, 2007, at 16:01 , Michael Glaesemann wrote:

> CREATE OR REPLACE FUNCTION one_when(BOOLEAN)
> RETURNS INTEGER
> LANGUAGE SQL as $_$SELECT value_when($1,1)$_$;

I forgot to add that you can cast booleans to integers, so one_when
(expr) is equivalent to expr::int:

# SELECT (true and false)::int, (true or false)::int;
int4 | int4
------+------
0 | 1
(1 row)

Of course, this rewriting shouldn't affect the performance at all: it
should just make it easier for you to read, which does have some value.

Michael Glaesemann
grzm seespotcode net

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Steve Crawford 2007-07-18 21:16:44 Will partial index creation use existing index?
Previous Message Pat Maddox 2007-07-18 21:12:14 Re: Need help optimizing this query