Re: SQL function and input variables

From: Susan Cassidy <scassidy(at)edgewave(dot)com>
To: Martín Marqués <martin(dot)marques(at)gmail(dot)com>, Thomas Kellerer <spam_eater(at)gmx(dot)net>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL function and input variables
Date: 2011-09-21 15:25:05
Message-ID: 3A51F387FE0CC74D80FA60C146987F2501C3D7B189F0@oc-exchange1.stbernard.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

You can do something like:
DECLARE
p ALIAS FOR $1;

in the function, if you want.

Susan

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org [mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Martín Marqués
Sent: Wednesday, September 21, 2011 6:09 AM
To: Thomas Kellerer
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: [GENERAL] SQL function and input variables

2011/9/21 Thomas Kellerer <spam_eater(at)gmx(dot)net>:
> Martín Marqués, 21.09.2011 14:56:
>>
>> I was makeing an SQL function and got an error which on a sintax that
>> I thouhgt would work:
>>
>> CREATE OR REPLACE FUNCTION dicInsertarPalabra(p TEXT)
>> RETURNS INT AS $body$
>>        INSERT INTO public.diccionario (palabra) VALUES (quote_literal(p));
>>        SELECT COALESCE(codigo,0) FROM public.diccionario
>>               WHERE palabra = quote_literal(p);
>> $body$ LANGUAGE 'SQL';
>>
>> Changing p for $1 in the body of the function makes it work. But,
>> can't we label input arguments like how I did here?
>>
> This is because the language SQL does not support named parameters, only
> positional ones.
>
> http://www.postgresql.org/docs/current/static/xfunc-sql.html#XFUNC-NAMED-PARAMETERS

Thanks for the tip. Didn't know that, and just kept using plpgsql sintax.

Thanks again.

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador

In response to

Browse pgsql-general by date

  From Date Subject
Next Message jablonov 2011-09-21 15:32:04 Re: Trigger Procedure Error: NEW used in query that is not in a rule
Previous Message Tom Lane 2011-09-21 15:20:17 Re: Upgrade extension from 8.4 to 9.1