Re: FUNCTION returns SETOF

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: FUNCTION returns SETOF
Date: 2006-05-23 13:49:25
Message-ID: 491.1148392165@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Rafal Pietrak <rafal(at)zorro(dot)isa-geek(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-05-23 13:55:20 Re: functions and plans
Previous Message Sim Zacks 2006-05-23 13:48:42 Re: table variables