Re: FUNCTION returns SETOF - Mailing list pgsql-general

From Tom Lane
Subject Re: FUNCTION returns SETOF
Date
Msg-id 491.1148392165@sss.pgh.pa.us
Whole thread Raw
In response to FUNCTION returns SETOF  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
List pgsql-general
Rafal Pietrak <rafal@zorro.isa-geek.com> writes:
> CREATE FUNCTION new_user (text,text) RETURNS SETOF people AS $$
>     CREATE ROLE $1 PASSWORD $2;
>     SELECT CASE WHEN $2 is not null THEN ROW($1, null, null, null)::people
> ELSE null::ludzie END
> $$ language sql;

> "ERROR:  function returning set of rows cannot return null value"

If you want to return no rows, then return no rows.  Something like

    SELECT ROW($1, null, null, null)::people WHERE $2 is not null;

            regards, tom lane

pgsql-general by date:

Previous
From: Sim Zacks
Date:
Subject: functions and plans
Next
From: Tom Lane
Date:
Subject: Re: functions and plans