Search Postgresql Archives

Re: Evaluate only one CASE WHEN in a select

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux