From: Sebastian Ritter <ritter.sebastian@gmail.com>
To: pgsql-sql@postgresql.org
Subject: PL/pgSQL question
Date: Thu, 14 Feb 2008 13:23:33 +0000
Message-ID: <99b656cb0802140523o165f69ebtcb4a42307c085f18@mail.gmail.com> (raw)
Hi all,
I have a question regarding functions. How can I return zero rows from a
function whose return type is a table row? I did the following test and it
did not work as expected:
CREATE OR REPLACE FUNCTION
fn_get_user (integer) RETURNS usertable AS '
DECLARE
in_userid ALIAS for $1;
resulter usertable%ROWTYPE;
BEGIN
IF in_userid IS NULL THEN
RAISE EXCEPTION ''No user provided'';
RETURN null;
END IF;
SELECT INTO resulter
usertable.*
FROM
usertable
WHERE
id = in_userid;
IF FOUND THEN
RETURN resulter;
ELSE
RETURN null;
END IF;
END;'LANGUAGE plpgsql;
>select * from fn_get_user(-1);
id | col1 | col2 | col3| name | email
----+------------+-------------+------------+--------
| | | | | |
(1 row)
This returns a null row. I am trying to make it behave such that it returns
zero rows like a straight select.
>select * from usertable where id =-1;
id | col1 | col2 | col3| name | email
----+------------+-------------+------------+--------
(0 rows)
Is this possible in anyway?
Regards,
Sebastian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: ritter.sebastian@gmail.com
Subject: Re: PL/pgSQL question
In-Reply-To: <99b656cb0802140523o165f69ebtcb4a42307c085f18@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox