PL/pgSQL syntax/usage question

From: Henk van Lingen <henkvl(at)cs(dot)uu(dot)nl>
To: pgsql-general(at)hub(dot)org
Subject: PL/pgSQL syntax/usage question
Date: 2000-02-01 14:57:02
Message-ID: Pine.GSO.4.21.0002011549280.25178-100000@sarastro.cs.uu.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)cs(dot)uu(dot)nl> |
| Dept. of Computer Science, Utrecht University. phone: +31-30-2535278 |
+----------------- http://www.cs.uu.nl/people/henkvl/ ------------------+

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Huynh, Long 2000-02-01 15:27:55 how do I unsubscribe to this?
Previous Message Arnaud FLORENT 2000-02-01 13:55:21 [GENERAL]