I've got two questions about plpgsql. Couldn't find the answer in the
manual nor anywhere on the net.
Let's say I've got a table A with columns (id integer, txt varchar) and
a function get_a(integer):
CREATE OR REPLACE FUNCTION get_a(integer) RETURNS a as '
SELECT * FROM a WHERE id=$1;
' LANGUAGE 'sql';
First question: it is possible that a non-existant id will be requested,
i need the function to return the same thing a normal select would
return - an empty result set. However I get an error whenever the select
returns nothing. The error is "Function returning row cannot return null
value". Is the only solution to this problem to declare function get_a
to return "SET OF a" ?
Second question I've got a plpgsql function in which I need the result
of my function get_a.
CREATE OR REPLACE FUNCTION do_stuff(integer) RETURNS integer as '
var := get_a($1);
' LANGUAGE 'plpgsql';
I get a syntex error on the line of the assignment (var := get_a($1)).
IF I replace the assignment with a "select into var * from get_a($1)"
then everything is ok. It also works with simple types (like varchar,
integer ant etc.), but not with row-types. Am I missing anything or is
record assignment not possible in plpgsql?
Thanks in advance,
pgsql-novice by date
|Next:||From: Tom Lane||Date: 2005-02-12 09:12:56|
|Subject: Re: plpgsql |
|Previous:||From: Sal Dkj||Date: 2005-02-12 00:38:23|
|Subject: Re: Converting interval to numeric?|