Re: Evaluate only one CASE WHEN in a select

From: Guy Rouillier <guyr-ml1(at)burntmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Evaluate only one CASE WHEN in a select
Date: 2007-04-15 00:35:42
Message-ID: 4621735E.8040103@burntmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

dcrespo wrote:
>
> SELECT
> CASE WHEN is_odd(t.number) THEN 'Update' ELSE 'Insert' END AS
> action,
> CASE WHEN is_odd(t.number) THEN t.number ELSE NULL END AS number,
> FROM ... ;
>
> As you can see, is_odd function (only a function example) is being run
> twice with exactly the same parameters to put a value into action
> field and into number field. Since it's the same function call, I want
> it to be run only once and put the above values into their
> corresponding fields. My actual function is not that expensive, but
> has to be run for every retrieved row, obviously. Does this change
> your explanation?

If your objective is to run a stored procedure once but return several
values, look at either defining multiple OUT parameters, or returning a
record type.

--
Guy Rouillier

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Michael Fuhr 2007-04-15 01:59:39 Re: pg_dump seg fault on sequences
Previous Message Tom Lane 2007-04-14 22:26:22 Re: pg_dump seg fault on sequences