pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@gmail.com>
To: pgsql-sql@postgresql.org
Cc: Pavel Stehule <pavel.stehule@gmail.com>
Cc: berelith <nicolasbeuzeboc@gmail.com>
Subject: Re: Need help with plpgsql function.
Date: Sun, 14 Nov 2010 10:37:58 -0800
Message-ID: <201011141037.59231.adrian.klaver@gmail.com> (raw)
In-Reply-To: <AANLkTikqf3bSwxJDHXmwanqfV9pNy1w5g_EdCRd0qA51@mail.gmail.com>
References: <1289692082542-3264047.post@n5.nabble.com>
	<AANLkTikqf3bSwxJDHXmwanqfV9pNy1w5g_EdCRd0qA51@mail.gmail.com>

On Saturday 13 November 2010 11:15:51 pm Pavel Stehule wrote:

> > }
>
> Hello
>
> you can use a RETURN QUERY statement - some like
>
> CREATE OR REPLACE FUNCTION foo(IN i int, OUT a int, OUT b int)
> RETURNS SETOF RECORD AS $$
> BEGIN
>   IF i = 1 THEN
>     RETURN QUERY SELECT 10,20 UNION ALL SELECT 30,40;
>   ELSE
>     RETURN QUERY SELECT 60,70 UNION ALL SELECT 80,90;
>   END IF;
>   RETURN;
> END;
> $$ LANGUAGE plpgsql;
>
> SELECT * FROM foo(1);
> SELECT * FROM foo(2);
>
> Regards
>
> Pavel Stehule
>

FYI the OP is using 8.2 :) RETURN QUERY is 8.3+ 

-- 
Adrian Klaver
adrian.klaver@gmail.com



view thread (4+ messages)  latest in thread

Message-ID: <201011141037.59231.adrian.klaver@gmail.com>
Permalink:  ../201011141037.59231.adrian.klaver@gmail.com/
Also on:    postgresql.org/message-id/201011141037.59231.adrian.klaver@gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: adrian.klaver@gmail.com, pavel.stehule@gmail.com, nicolasbeuzeboc@gmail.com
  Subject: Re: Need help with plpgsql function.
  In-Reply-To: <201011141037.59231.adrian.klaver@gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox