Re: returning more than one value from a function

From: Lonni J Friedman <netllama(at)gmail(dot)com>
To: Leif Biberg Kristensen <leif(at)solumslekt(dot)org>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: returning more than one value from a function
Date: 2010-05-01 22:49:10
Message-ID: u2x7c1574a91005011549h4a5485behd7c76dea02d38d39@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)solumslekt(dot)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(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice
>

--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L. Friedman netllama(at)gmail(dot)com
LlamaLand https://netllama.linux-sxs.org

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2010-05-01 22:56:07 Re: returning more than one value from a function
Previous Message Mary Anderson 2010-05-01 17:30:35 Re: Last modification date for Triggers, functions, tables ....