PL/pgSQL syntax/usage question - Mailing list pgsql-general

From Henk van Lingen
Subject PL/pgSQL syntax/usage question
Date
Msg-id Pine.GSO.4.21.0002011549280.25178-100000@sarastro.cs.uu.nl
Whole thread Raw
List pgsql-general
Hi *,

I'm starting with PL/pgSQL but can't exactly find out how to do
something like this:

CREATE FUNCTION textkey (text, int4) RETURNS text AS '
        DECLARE
                tabel ALIAS FOR $1;
                id ALIAS FOR $2;
                result record;
        BEGIN
                select lname into result from tabel
                where person_id=id;
                return result;
        END;
    ' LANGUAGE 'plpgsql';

csbase=> select textkey ('person',111) as result;
ERROR:  parser: parse error at or near "$1"

postmaster.log:

StartTransactionCommand
query: select textkey ('person',111) as result;
ProcessQuery
query: SELECT lname from $1 where person_id=$2
ERROR:  parser: parse error at or near "$1"
DEBUG:  Last error occured while executing PL/pgSQL function textkey
DEBUG:  line 6 at select into variables
AbortCurrentTransaction


How does one do things like this? Why aren't the $n variables expanded
in the logfile?

Maybe it is documented but I can't find it in chapter 11 of the Programmer's
Guide. Are there other places where PL/pgSQL is explained?

By the way: I'm using 6.5.2 on RedHat 6.1

Regards,
+-----------------------------------------------------------------------+
| Henk van Lingen, Systems Administrator,             <henkvl@cs.uu.nl> |
| Dept. of Computer Science, Utrecht University.  phone: +31-30-2535278 |
+----------------- http://www.cs.uu.nl/people/henkvl/ ------------------+


pgsql-general by date:

Previous
From: Arnaud FLORENT
Date:
Subject: [GENERAL]
Next
From: "Huynh, Long"
Date:
Subject: how do I unsubscribe to this?