Search Postgresql Archives

R: Re: Function with DEFAULT arguments

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, thanks for the quick reply and the link!

Dario

>----Messaggio originale----
>Da: depesz@xxxxxxxxxx
>Data: 12/03/2010 17.38
>A: "dario.ber@xxxxxxxxx"<dario.ber@xxxxxxxxx>
>Cc: <pgsql-general@xxxxxxxxxxxxxx>
>Ogg: Re:  Function with DEFAULT arguments
>
>On Fri, Mar 12, 2010 at 05:28:57PM +0100, dario.ber@xxxxxxxxx wrote:
>> Hello,
>> 
>> I'm trying to use the DEFAULT option to pass parameters to the arguments of 
a 
>> function. 
>> When I call that function, how can I change the default value of some 
>> arguments and leave as default the value of other arguments? In other 
words, is 
>> there a way to 'call' the arguments by their names so to specify which 
should 
>> have their default value changed?
>> 
>> Here's a toy example, a function that takes three strings as arguments and 
>> concatenate them:
>> 
>> CREATE FUNCTION test_default(string1 text default 'a', string2 text 
default 
>> 'b', string3 text default 'c') RETURNS text AS $$
>> BEGIN
>> RETURN string1 || string2 || string3;
>> END;
>> $$ language 'plpgsql';
>> 
>> -- Only default args:
>> SELECT test_default();   --> abc
>> 
>> -- With custom values:
>> SELECT test_default('X', 'Y', 'Z'); --> XYZ
>> 
>> -- Now, how can I leave as default the 1st and 3rd argument (string1 and 
>> string3) and change only the second one (string2)? I would like to do 
something 
>> like:
>
>You can't unless you're on PostgreSQL 9.0:
>http://www.depesz.com/index.php/2009/11/17/waiting-for-8-5-named-function-
arguments/
>
>depesz
>
>-- 
>Linkedin: http://www.linkedin.com/in/depesz  /  blog: http://www.depesz.com/
>jid/gtalk: depesz@xxxxxxxxxx / aim:depeszhdl / skype:depesz_hdl / gg:6749007
>



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux