Re: WIP: default values for function parameters

From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "David E(dot) Wheeler" <david(at)kineticode(dot)com>
Cc: "Heikki Linnakangas" <heikki(dot)linnakangas(at)enterprisedb(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Gregory Stark" <stark(at)enterprisedb(dot)com>, "Grzegorz Jaskiewicz" <gj(at)pointblue(dot)com(dot)pl>, "PostgreSQL Hackers" <pgsql-hackers(at)postgresql(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Subject: Re: WIP: default values for function parameters
Date: 2008-12-12 14:56:56
Message-ID: 162867790812120656s1fb269d6lcbffbce10cbfc651@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2008/12/12 David E. Wheeler <david(at)kineticode(dot)com>:
> On Dec 12, 2008, at 3:38 PM, Pavel Stehule wrote:
>
>> I discussed about this form with Tom.
>>
>> I thing so following should be readable:
>>
>> name: [ optional => ] value
>>
>> SELECT foo( bar: 'ick', baz: 'ack' );
>> SELECT foo( bar: => 'ick', baz: => 'ack' );
>>
>> or
>>
>> SELECT foo( bar: = 'ick', baz: = 'ack' );
>>
>> reason for optional using of "=>" is too thin char ":", so =>
>> optically boost the colon.
>
> Hrm. I can see that, I guess. In that case, though, I think I'd prefer the
> colon at the beginning of the parameter label:
>
> SELECT foo( :bar => 'ick', :baz => 'ack' );

this syntax is used yet
http://www.postgresql.org/docs/8.3/interactive/app-psql.html

testdb=> \set foo 'my_table'
testdb=> SELECT * FROM :foo;

would then query the table my_table. The value of the variable is
copied literally, so it can even contain unbalanced quotes or
backslash commands. You must make sure that it makes sense where you
put it. Variable interpolation will not be performed into quoted SQL
entities.

A popular application of this facility is to refer to the last
inserted OID in subsequent statements to build a foreign key scenario.
Another possible use of this mechanism is to copy the contents of a
file into a table column. First load the file into a variable and then
proceed as above:

testdb=> \set content '''' `cat my_file.txt` ''''
testdb=> INSERT INTO my_table VALUES (:content);

regards
Pavel Stehule

>
> In that case, though, I'd want the => to be required. Note that there's a
> precedent here, too: This is Ruby's syntax for using "symbols" for parameter
> names.
>
>> this is 100% compatible because syntax name: is new token
>
> Interesting. I hadn't expected that the use of the colon to make the use of
> => be okay. Cool that it does, though.
>
> Best,
>
> David
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Gregory Stark 2008-12-12 14:57:52 Re: WIP: default values for function parameters
Previous Message Tom Lane 2008-12-12 14:54:02 Re: benchmarking the query planner