On Mon, Nov 29, 2004 at 01:37:42PM -0500, RobertD(dot)Stewart(at)ky(dot)gov wrote:
> I have tried to create a simple function to select data from a table. Could
> you all please correct me
It would be helpful if you told us what you want to happen and what
actually does happen. Without that information we have to guess
at your intentions.
> CREATE FUNCTION retrive_atype(varchar) RETURNS varchar AS '
> RETURN select username from masteraccount where atype=$1;
> ' LANGUAGE 'plpgsql';
> To call the function I used
> Select retrive_atype();
You've defined the function to take a VARCHAR argument but you
called it without an argument. Also, you've defined it to return
a single VARCHAR value, but if the query could return multiple
values then the function should return SETOF VARCHAR. Maybe this
is closer to what you need:
CREATE FUNCTION retrive_atype(VARCHAR) RETURNS SETOF VARCHAR AS '
FOR rec IN SELECT username FROM masteraccount WHERE atype = $1 LOOP
RETURN NEXT rec.username;
' LANGUAGE plpgsql;
You'd call the function like this:
SELECT * FROM retrive_atype('some-atype-value');
If that's not what you're looking for then please provide more details.
BTW, is "retrive" supposed to be "retrieve"?
In response to
pgsql-sql by date
|Next:||From: Nurdin||Date: 2004-11-30 02:57:12|
|Subject: create stored procedure from temporary table|
|Previous:||From: Johan Henselmans||Date: 2004-11-29 20:26:13|
|Subject: grouping a many to many relation set|