RE: [GENERAL] PL/pgSQL syntax/usage question

From: Stephane FILLON <fillons(at)offratel(dot)nc>
To: "'Henk van Lingen'" <henkvl(at)cs(dot)uu(dot)nl>, "pgsql-general(at)hub(dot)org" <pgsql-general(at)hub(dot)org>
Subject: RE: [GENERAL] PL/pgSQL syntax/usage question
Date: 2000-02-03 03:59:10
Message-ID: 01BF6E73.81133FC0.fillons@offratel.nc
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Message d'origine-----
> De: Henk van Lingen [SMTP:henkvl(at)cs(dot)uu(dot)nl]
> Date: mercredi 2 fevrier 2000 01:57
> A: pgsql-general(at)hub(dot)org
> Objet: [GENERAL] PL/pgSQL syntax/usage question
>
> 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
>

Replace the line "where person_id=id" with "where person_id = id".

Add a space between = and id as PL/pgSQL trie to interpret the operator =$2 that doesn't exist.

Regards,

Stephane FILLON

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2000-02-03 04:02:44 Re: [SQL] Proposed Changes to PostgreSQL
Previous Message Bruce Momjian 2000-02-03 03:58:41 Re: [HACKERS] Re: [SQL] Re: [GENERAL] Proposed Changes to PostgreSQL