FW: PL/pgSQL Function Help

From: "Niblett, David A" <niblettda(at)gru(dot)com>
To: <pgsql-general(at)postgresql(dot)org>
Subject: FW: PL/pgSQL Function Help
Date: 2005-12-16 21:04:59
Message-ID: 94FE9AAAB50C92448DCF1A4B99816F660284A5@GRUCLXCHGPR01.gruadmin.gru.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Well that kills two birds. I completely didn't understand
the difference between SETOF and just RECORD return types.

That fixed it up, and for the record here is what the function looks
like now.

CREATE TYPE myrec AS (
id int
);

CREATE OR REPLACE FUNCTION test(x int) RETURNS SETOF myrec
AS '
DECLARE
output RECORD;
BEGIN
IF x THEN
RETURN;
END IF;

SELECT INTO output 9999;
RETURN NEXT output;
RETURN;
END;
'
LANGUAGE plpgsql;

xxx=# select * from test(1);
id
----
(0 rows)

xxx=# select * from test(0);
id
------
9999
(1 row)

Thanks Tom!

--
David

-----Original Message-----
From: Tom Lane [mailto:tgl(at)sss(dot)pgh(dot)pa(dot)us]
Sent: Friday, December 16, 2005 3:30 PM
To: Niblett, David A
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] PL/pgSQL Function Help

"Niblett, David A" <niblettda(at)gru(dot)com> writes:
> Is there no way in Postgres that I can simply not return anything so I
> show zero rows?

Make the function return SETOF myrec not just myrec. Then you can
return zero or one (or more) myrec's.

regards, tom lane

Browse pgsql-general by date

  From Date Subject
Next Message Jim C. Nasby 2005-12-16 21:18:04 Re: How to store the time zone with a timestamp
Previous Message Karsten Hilbert 2005-12-16 20:58:47 Re: Transacciones Anidadas