Re: returning more than one value from a function - Mailing list pgsql-novice

From Lonni J Friedman
Subject Re: returning more than one value from a function
Date
Msg-id u2x7c1574a91005011549h4a5485behd7c76dea02d38d39@mail.gmail.com
Whole thread Raw
In response to Re: returning more than one value from a function  (Leif Biberg Kristensen <leif@solumslekt.org>)
Responses Re: returning more than one value from a function  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Thanks for your reply.  Luiz Neri replied privately to me last Friday,
and suggested that I use a 'SELECT INTO ...' query inside the function
to put the result of the query into a temp table.  That seems to be
working out ok, with one unfortunate side effect.  Now I've got the
opposite problem, namely that I can't find a way to have my function
not return anything at all.  Whenever I try to remove the 'RETURN AS
....' portion of the function, it fails to get created.  Is it not
possible to have a function that returns nothing?

thanks!

On Sat, May 1, 2010 at 4:43 AM, Leif Biberg Kristensen
<leif@solumslekt.org> wrote:
> On Friday 30. April 2010 18.37.34 Lonni J Friedman wrote:
>> Greetings,
>> I'm attempting to create a PL/PGSQL function with an IF/THEN
>> conditional.  Basically, all I really need is the ability to run a
>> long/complex SQL query based on the value of the newest row of one
>> column in a specific table (if its equal to 1 then run the SQL, if
>> anything else don't run it).  In pseudo code, something like:
>>
>> CREATE OR REPLACE FUNCTION foo0 RETURN text AS $$
>> IF (SELECT current_status from table0 WHERE id in (SELECT max(id) FROM
>> table0))='1' THEN
>>      <LONG SQL QUERY>
>> END IF;
>> LANGUAGE 'plpgsql' ;
>>
>>
>> This seems like a fairly simple requirement, yet I can't find any way
>> to do this without creating a function.  The problem is that the
>> long/complex SQL query needs to return multiple columns of output (not
>> just a single value), and functions can only return a single
>> value/column, so I'm a bit stuck on how to make this work.
>>
>> Is there an alternative solution that I'm missing?
>
> Don't know if you're aware of the CASE WHEN ... ELSE ... END construct, which
> is vanilla SQL, and is very similar to the usual IF ... THEN ... ELSE.
> <http://www.postgresql.org/docs/current/static/functions-
> conditional.html#AEN15201>
>
> regards,
> --
> Leif Biberg Kristensen
> http://solumslekt.org/
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>



--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L. Friedman                                    netllama@gmail.com
LlamaLand                       https://netllama.linux-sxs.org

pgsql-novice by date:

Previous
From: Mary Anderson
Date:
Subject: Re: Last modification date for Triggers, functions, tables ....
Next
From: Tom Lane
Date:
Subject: Re: returning more than one value from a function