Re: how to return ONE single record from a function in plpgsql? - Mailing list pgsql-sql

From Tom Lane
Subject Re: how to return ONE single record from a function in plpgsql?
Date
Msg-id 5776.1046018061@sss.pgh.pa.us
Whole thread Raw
In response to how to return ONE single record from a function in plpgsql?  (Hubert depesz Lubaczewski <depesz@depesz.pl>)
Responses Re: how to return ONE single record from a function in plpgsql?
List pgsql-sql
Hubert depesz Lubaczewski <depesz@depesz.pl> writes:
> i was thinking about using something like:
> CREATE type helper_login as (logged bool, username TEXT, points INT8,
> first_login bool, admin bool, last_login timestamptz, can_ask_questions
> bool, timeleft INTERVAL);
> CREATE OR REPLACE FUNCTION login(TEXT, TEXT, INT8) RETURNS helper_login
> AS '
> DECLARE 
>         in_username          ALIAS FOR $1;
>         in_password          ALIAS FOR $2;
>         in_quiz_id           ALIAS FOR $3;
>         reply helper_login;

You need to say  reply helper_login%ROWTYPE;
otherwise plpgsql doesn't realize that this is supposed to be a rowtype
variable.  (That could stand to be improved, but no one's gotten around
to it yet.)  See
http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/plpgsql-declarations.html#PLPGSQL-DECLARATION-ROWTYPES
        regards, tom lane


pgsql-sql by date:

Previous
From: "Wayne Armstrong"
Date:
Subject: Porting from db2 problem
Next
From: Eddie Cheung
Date:
Subject: Help with query involving aggregation and joining.