Re: Returning 0 rows from a PL/PGSQL

Поиск
Список
Период
Сортировка
От Stephan Szabo
Тема Re: Returning 0 rows from a PL/PGSQL
Дата
Msg-id 20050219165158.L99167@megazone.bigpanda.com
обсуждение исходный текст
Ответ на Returning 0 rows from a PL/PGSQL  (Vitaly Belman <vitalyb@gmail.com>)
Ответы Re: Returning 0 rows from a PL/PGSQL  (Vitaly Belman <vitalyb@gmail.com>)
Список pgsql-general
On Sun, 20 Feb 2005, Vitaly Belman wrote:

> I have the following plpgsql function:
>
> CREATE OR REPLACE FUNCTION public."temp"(int4)
>   RETURNS public.books AS
> $BODY$DECLARE
>     old_book books%rowtype;
> BEGIN
>     select * into old_book from books
>     where book_id = var_book_id;
>
>     IF FOUND = false THEN
>         return null;
>     ELSE
>         return old_book;
>     END IF;
> END;$BODY$
>   LANGUAGE 'plpgsql' VOLATILE;
>
> If the function finds a book with the given ID, it returns its row, if
> it doesn't, it should return no rows at all (naturally it is
> simplified version of what I need). In practice, however, it returns
> either a regular row, or a regular row with all fields set to NULL.

I think you'd need to make the function a set returning one in order to
potentially return no rows (which I think would involve making it returns
setof public.books, doing a return next old_book when found=true and
nothing in the false case and putting a return at the end).


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: quoting internal variable names
Следующее
От: John DeSoi
Дата:
Сообщение: Re: PGSQL 8.0.1 Win 2K Installation Problem