FW: PL/pgSQL Function Help

Поиск
Список
Период
Сортировка
От Niblett, David A
Тема FW: PL/pgSQL Function Help
Дата
Msg-id 94FE9AAAB50C92448DCF1A4B99816F660284A5@GRUCLXCHGPR01.gruadmin.gru.com
обсуждение исходный текст
Список 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@sss.pgh.pa.us]
Sent: Friday, December 16, 2005 3:30 PM
To: Niblett, David A
Cc: pgsql-general@postgresql.org
Subject: Re: [GENERAL] PL/pgSQL Function Help


"Niblett, David A" <niblettda@gru.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

В списке pgsql-general по дате отправления:

Предыдущее
От: Karsten Hilbert
Дата:
Сообщение: Re: Transacciones Anidadas
Следующее
От: "Jim C. Nasby"
Дата:
Сообщение: Re: How to store the time zone with a timestamp