RE: [GENERAL] PL/pgSQL syntax/usage question - Mailing list pgsql-general

From Stephane FILLON
Subject RE: [GENERAL] PL/pgSQL syntax/usage question
Date
Msg-id 01BF6E73.81133FC0.fillons@offratel.nc
Whole thread Raw
List pgsql-general
> -----Message d'origine-----
> De:    Henk van Lingen [SMTP:henkvl@cs.uu.nl]
> Date:    mercredi 2 fevrier 2000 01:57
> A:    pgsql-general@hub.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

pgsql-general by date:

Previous
From: Chris Bitmead
Date:
Subject: Re: [SQL] Re: [GENERAL] Proposed Changes to PostgreSQL
Next
From: "Mark Alliban"
Date:
Subject: Re: [GENERAL] Re: Poor performance - need advice