Re: Evaluate only one CASE WHEN in a select - Mailing list pgsql-general

From Guy Rouillier
Subject Re: Evaluate only one CASE WHEN in a select
Date
Msg-id 4621735E.8040103@burntmail.com
Whole thread Raw
In response to Re: Evaluate only one CASE WHEN in a select  ("dcrespo" <dcrespo@gmail.com>)
List 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

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: pg_dump seg fault on sequences
Next
From: Michael Fuhr
Date:
Subject: Re: pg_dump seg fault on sequences