Re: SQL function and input variables

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: SQL function and input variables
Date: 2011-09-21 13:07:24
Message-ID: j5cnh4$7um$1@dough.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Thomas

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martín Marqués 2011-09-21 13:09:21 Re: SQL function and input variables
Previous Message Raymond O'Donnell 2011-09-21 13:04:51 Re: SQL function and input variables