proposal sql: labeled function params

Lists: pgsql-hackers
From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal sql: labeled function params
Date: 2008-08-14 09:56:58
Message-ID: 162867790808140256w533324bj25183d476d3aa89a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I propose enhance current syntax that allows to specify label for any
function parameter:

fcename(expr [as label], ...)
fcename(colname, ...)

I would to allow same behave of custom functions like xmlforest function:
postgres=# select xmlforest(a) from foo;
xmlforest
-----------
<a>10</a>
(1 row)

postgres=# select xmlforest(a as b) from foo;
xmlforest
-----------
<b>10</b>
(1 row)

Actually I am not sure what is best way for PL languages for acces to
these info. Using some system variables needed new column in pg_proc,
because collecting these needs some time and in 99% cases we don't
need it. So I prefere some system function that returns labels for
outer function call. Like

-- test
create function getlabels() returns varchar[] as $$select '{name,
age}'::varchar[]$$ language sql immutable;

create or replace function json(variadic varchar[])
returns varchar as $$
select '[' || array_to_string(
array(
select (getlabels())[i]|| ':' || $1[i]
from generate_subscripts($1,1) g(i))
,',') || ']'
$$ language sql immutable strict;

postgres=# select json('Zdenek' as name,'30' as age);
json
----------------------
[name:Zdenek,age:30]
(1 row)

postgres=# select json(name, age) from person;
json
----------------------
[name:Zdenek,age:30]
(1 row)

There are two possibilities
a) collect labels in parse time
b) collect labels in executor time

@a needs info in pg_proc, but it is simpler, @b is little bit
difficult, but doesn't need any changes in system catalog. I thinking
about b now.

Necessary changes:
=================
labels are searched in parse tree fcinfo->flinfo->fn_expr. I need
insert label into parse tree, so I it needs special node
labeled_param, For getting column reference I need to put current
exprstate to fcinfo. Function getlabels() should take code from
ExecEvalVar function.

Any notes, ideas?

Pavel Stehule


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-14 21:05:56
Message-ID: 1218747956.14869.20.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 2008-08-14 at 11:56 +0200, Pavel Stehule wrote:
> Hello
>
> I propose enhance current syntax that allows to specify label for any
> function parameter:
>
> fcename(expr [as label], ...)
> fcename(colname, ...)

also fcename(localvar, ...) if called from another function ?

How is this supposed to interact with argument names ?

> I would to allow same behave of custom functions like xmlforest function:
> postgres=# select xmlforest(a) from foo;
> xmlforest
> -----------
> <a>10</a>
> (1 row)
>
> postgres=# select xmlforest(a as b) from foo;
> xmlforest
> -----------
> <b>10</b>
> (1 row)

Why not just have two arguments to xmlforest(label text,value text) like
this:

"select xmlforest('b', a) from foo"

?

> Actually I am not sure what is best way for PL languages for acces to
> these info. Using some system variables needed new column in pg_proc,
> because collecting these needs some time and in 99% cases we don't
> need it.

Exactly, maybe it is just a bad idea in general to pass the label info
into functions using some special syntax ?

what is wrong with passing it in regular arguments ?

I see very little gain from complicating the syntax (and function API).

maybe we will some time have keyword arguments as well and then have to
deal with syntax like

select func(arg4=7 as 'labelfor4')

> So I prefere some system function that returns labels for
> outer function call. Like
>
> -- test
> create function getlabels() returns varchar[] as $$select '{name,
> age}'::varchar[]$$ language sql immutable;
>
> create or replace function json(variadic varchar[])
> returns varchar as $$
> select '[' || array_to_string(
> array(
> select (getlabels())[i]|| ':' || $1[i]
> from generate_subscripts($1,1) g(i))
> ,',') || ']'
> $$ language sql immutable strict;

just write the function to take arguments as pairs (value, 'label', ...)

select json('Zdenek', 'name','30', 'age');

select json(name, 'name', age, 'age') from person;

> postgres=# select json('Zdenek' as name,'30' as age);
> json
> ----------------------
> [name:Zdenek,age:30]
> (1 row)
>
> postgres=# select json(name, age) from person;
> json
> ----------------------
> [name:Zdenek,age:30]
> (1 row)

why special-case table fields ?

what if you wanted to rename any table fields ?

> There are two possibilities
> a) collect labels in parse time
> b) collect labels in executor time
>
> @a needs info in pg_proc, but it is simpler, @b is little bit
> difficult, but doesn't need any changes in system catalog. I thinking
> about b now.
>
> Necessary changes:
> =================
> labels are searched in parse tree fcinfo->flinfo->fn_expr. I need
> insert label into parse tree, so I it needs special node
> labeled_param, For getting column reference I need to put current
> exprstate to fcinfo. Function getlabels() should take code from
> ExecEvalVar function.
>
> Any notes, ideas?

To me, this whole thing feels backwards - in described cases "labels"
seem to be just like any other data and I don't think it justifies a
special syntax.

---------------
Hannu


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, PostgreSQL-development Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 04:27:04
Message-ID: 9920.1218774424@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> How is this supposed to interact with argument names ?

Yeah, the real problem with this proposal is that it conscripts a syntax
that we'll probably want to use in the future for argument-name-based
parameter matching. The proposed behavior is not nearly as useful as
that would be.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 06:22:58
Message-ID: 162867790808142322s31efbc54lafbbfcc3a16c02d1@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/14 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Thu, 2008-08-14 at 11:56 +0200, Pavel Stehule wrote:
>> Hello
>>
>> I propose enhance current syntax that allows to specify label for any
>> function parameter:
>>
>> fcename(expr [as label], ...)
>> fcename(colname, ...)
>
> also fcename(localvar, ...) if called from another function ?
>
juju

> How is this supposed to interact with argument names ?

There is no interaction between argument names and labels. Primary
case is an using together variadic function where mostly parameters
are in one real parameter.

>
>> I would to allow same behave of custom functions like xmlforest function:
>> postgres=# select xmlforest(a) from foo;
>> xmlforest
>> -----------
>> <a>10</a>
>> (1 row)
>>
>> postgres=# select xmlforest(a as b) from foo;
>> xmlforest
>> -----------
>> <b>10</b>
>> (1 row)
>
> Why not just have two arguments to xmlforest(label text,value text) like
> this:
>
> "select xmlforest('b', a) from foo"
>

syntax ... (a as b) is used now in SQL/XML - it's not new concept.
This concept allows shorter queries, because in some cases (where
column name is same as label name), you don't need write label. So
this is only generalisation of actually used concept.

> ?
>
>> Actually I am not sure what is best way for PL languages for acces to
>> these info. Using some system variables needed new column in pg_proc,
>> because collecting these needs some time and in 99% cases we don't
>> need it.
>
> Exactly, maybe it is just a bad idea in general to pass the label info
> into functions using some special syntax ?
>
> what is wrong with passing it in regular arguments ?
>

I thougs about $0 - but it's occupeted now.

> I see very little gain from complicating the syntax (and function API).
>
> maybe we will some time have keyword arguments as well and then have to
> deal with syntax like
>
> select func(arg4=7 as 'labelfor4')
>

it's inconsistent with column labels :(. So better select func(arg4=7
as labelfor4) or select func(arg4=column4), ... but his syntax
collidate with boolean expression. Oracle use => operator

Sal_raise(Sal_incr=>500, Emp_id=>7369) and I am for respect this syntax.

>
>
>> So I prefere some system function that returns labels for
>> outer function call. Like
>>
>> -- test
>> create function getlabels() returns varchar[] as $$select '{name,
>> age}'::varchar[]$$ language sql immutable;
>>
>> create or replace function json(variadic varchar[])
>> returns varchar as $$
>> select '[' || array_to_string(
>> array(
>> select (getlabels())[i]|| ':' || $1[i]
>> from generate_subscripts($1,1) g(i))
>> ,',') || ']'
>> $$ language sql immutable strict;
>
> just write the function to take arguments as pairs (value, 'label', ...)
>
> select json('Zdenek', 'name','30', 'age');
>
> select json(name, 'name', age, 'age') from person;

it's possible, sure. But then I have to repeat label when label is
known from column name.

>
>
>> postgres=# select json('Zdenek' as name,'30' as age);
>> json
>> ----------------------
>> [name:Zdenek,age:30]
>> (1 row)
>>
>> postgres=# select json(name, age) from person;
>> json
>> ----------------------
>> [name:Zdenek,age:30]
>> (1 row)
>
> why special-case table fields ?
>
???
or structured types .. there isn't case, you can put inside only one
scalar attribut - but it's true - it would to accept fields some like:

create type person as (name varchar, age integer);

select json(a.name, a.age, b.name, b.age) from ...
and generate [a.name: ...., a.age: ....

> what if you wanted to rename any table fields ?
>

it's not renaming, It's function metadata (and default is generated
from column names).

>> There are two possibilities
>> a) collect labels in parse time
>> b) collect labels in executor time
>>
>> @a needs info in pg_proc, but it is simpler, @b is little bit
>> difficult, but doesn't need any changes in system catalog. I thinking
>> about b now.
>>
>> Necessary changes:
>> =================
>> labels are searched in parse tree fcinfo->flinfo->fn_expr. I need
>> insert label into parse tree, so I it needs special node
>> labeled_param, For getting column reference I need to put current
>> exprstate to fcinfo. Function getlabels() should take code from
>> ExecEvalVar function.
>>
>> Any notes, ideas?
>
> To me, this whole thing feels backwards - in described cases "labels"
> seem to be just like any other data and I don't think it justifies a
> special syntax.
>
> ---------------
> Hannu
>
>
>
>
>
>
>


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "PostgreSQL-development Hackers" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 06:32:01
Message-ID: 162867790808142332r2b8206efh12924f6467709454@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/15 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> How is this supposed to interact with argument names ?
>
> Yeah, the real problem with this proposal is that it conscripts a syntax
> that we'll probably want to use in the future for argument-name-based
> parameter matching. The proposed behavior is not nearly as useful as
> that would be.

It isn't. As Hannu showed these features should live in harmony (if we
will accept Oracle's syntax). I see as real problem new column in
pg_proc, that allow quickly chose between labeled and non labeled
functions - and then collect labels in parse time. This is way for
adding parameter info into variadic function - it's main goal of this
proposal. Without column in pg_proc it could same slowdowns like first
variadic function's implementation.

Regards
Pavel Stehule
>
> regards, tom lane
>


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 12:52:51
Message-ID: 200808151552.53466.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Am Thursday, 14. August 2008 schrieb Pavel Stehule:
> I propose enhance current syntax that allows to specify label for any
> function parameter:
>
> fcename(expr [as label], ...)
> fcename(colname, ...)
>
> I would to allow  same behave of custom functions like xmlforest function:
> postgres=# select xmlforest(a) from foo;
>  xmlforest
> -----------
>  <a>10</a>
> (1 row)

Do you have a use case for this outside of XML?


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 12:54:26
Message-ID: 162867790808150554obc5b85dpd1c52dd497e911ee@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/15 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> Am Thursday, 14. August 2008 schrieb Pavel Stehule:
>> I propose enhance current syntax that allows to specify label for any
>> function parameter:
>>
>> fcename(expr [as label], ...)
>> fcename(colname, ...)
>>
>> I would to allow same behave of custom functions like xmlforest function:
>> postgres=# select xmlforest(a) from foo;
>> xmlforest
>> -----------
>> <a>10</a>
>> (1 row)
>
> Do you have a use case for this outside of XML?
>

JSON and similar (custom) protocols

Pavel


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Hannu Krosing <hannu(at)2ndquadrant(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 13:03:10
Message-ID: 200808151603.12021.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Am Friday, 15. August 2008 schrieb Tom Lane:
> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> > How is this supposed to interact with argument names ?
>
> Yeah, the real problem with this proposal is that it conscripts a syntax
> that we'll probably want to use in the future for argument-name-based
> parameter matching. The proposed behavior is not nearly as useful as
> that would be.

I am not at all convinced about the proposed feature, but is that really a
syntax we would use for function calls with named parameters?

Random googling shows me that Oracle appears to use a syntax like

name => value

This is actually a feature that I would like to see implemented soonish, so if
anyone has input on the possible syntax consequences, please comment.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 13:31:09
Message-ID: 162867790808150631ofe63911x5d645cd86b9d8680@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/15 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> Am Friday, 15. August 2008 schrieb Tom Lane:
>> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> > How is this supposed to interact with argument names ?
>>
>> Yeah, the real problem with this proposal is that it conscripts a syntax
>> that we'll probably want to use in the future for argument-name-based
>> parameter matching. The proposed behavior is not nearly as useful as
>> that would be.
>
> I am not at all convinced about the proposed feature, but is that really a
> syntax we would use for function calls with named parameters?
>
> Random googling shows me that Oracle appears to use a syntax like
>
> name => value
>

I vote this syntax too. So this second feature - named params X labels
for params. Labels for params is related to my work on variadic
functions. Named params needs default param's values - and some more
of changes in parser. Somebody have to solve conflict between params
and expression.

Pavel

> This is actually a feature that I would like to see implemented soonish, so if
> anyone has input on the possible syntax consequences, please comment.
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Hannu Krosing <hannu(at)2ndquadrant(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 14:01:36
Message-ID: 20284.1218808896@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> Random googling shows me that Oracle appears to use a syntax like
> name => value
> This is actually a feature that I would like to see implemented soonish, so if
> anyone has input on the possible syntax consequences, please comment.

We've been over this territory before. The problem with "name => value"
is that it requires reserving a perfectly good user-defined operator name.
"value AS name", on the other hand, accomplishes the same in a more
SQL-looking fashion with no new reserved word (since AS is already
fully reserved).

regards, tom lane


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 18:20:47
Message-ID: 1218824447.7387.13.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, 2008-08-15 at 10:01 -0400, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > Random googling shows me that Oracle appears to use a syntax like
> > name => value
> > This is actually a feature that I would like to see implemented soonish, so if
> > anyone has input on the possible syntax consequences, please comment.
>
> We've been over this territory before. The problem with "name => value"
> is that it requires reserving a perfectly good user-defined operator name.

We could declare, that using operator => in function argument expression
requires parenthesis : func( a => (b => c) means param a with value
expression (b => c) nad just func((b => c)) means first param with value
(b=>c)

the main use of named params is calling functions with default values,
and giving some params. there I'm more concerned about default args and
rules for finding right function in presence of functions with both
multiple args and default values for some.

create function f(a int) ...

create function f(a int, b int default 7)

create function f(text text)

and then calling f(4) - which one would it call

what about f('4')

Of course, we could also have default values without named params, and
just require keyword DEFAULT where we want default value :)

> "value AS name", on the other hand, accomplishes the same in a more
> SQL-looking fashion with no new reserved word (since AS is already
> fully reserved).

would it be more natural / SQL-like to use "value AS name" or "name AS
value" ?

-------------
Hannu


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-15 19:24:44
Message-ID: 1218828284.7387.17.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Fri, 2008-08-15 at 14:54 +0200, Pavel Stehule wrote:
> 2008/8/15 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> > Am Thursday, 14. August 2008 schrieb Pavel Stehule:
> >> I propose enhance current syntax that allows to specify label for any
> >> function parameter:
> >>
> >> fcename(expr [as label], ...)
> >> fcename(colname, ...)
> >>
> >> I would to allow same behave of custom functions like xmlforest function:
> >> postgres=# select xmlforest(a) from foo;
> >> xmlforest
> >> -----------
> >> <a>10</a>
> >> (1 row)
> >
> > Do you have a use case for this outside of XML?
> >
>
> JSON and similar (custom) protocols

why not use a format string, or any other separate (sub)language ?

select json('[name:$1, age: $2]', name, age) from students;

------------
Hannu


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 06:38:41
Message-ID: 162867790808152338h42b31d7bh80781565de655284@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/15 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Fri, 2008-08-15 at 14:54 +0200, Pavel Stehule wrote:
>> 2008/8/15 Peter Eisentraut <peter_e(at)gmx(dot)net>:
>> > Am Thursday, 14. August 2008 schrieb Pavel Stehule:
>> >> I propose enhance current syntax that allows to specify label for any
>> >> function parameter:
>> >>
>> >> fcename(expr [as label], ...)
>> >> fcename(colname, ...)
>> >>
>> >> I would to allow same behave of custom functions like xmlforest function:
>> >> postgres=# select xmlforest(a) from foo;
>> >> xmlforest
>> >> -----------
>> >> <a>10</a>
>> >> (1 row)
>> >
>> > Do you have a use case for this outside of XML?
>> >
>>
>> JSON and similar (custom) protocols
>
> why not use a format string, or any other separate (sub)language ?
>
> select json('[name:$1, age: $2]', name, age) from students;
>

because you have to write labels, where labels are equal with column
names. I would to add same comfort like SQL/XML functions.

Pavel

> ------------
> Hannu
>
>


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 06:44:15
Message-ID: 162867790808152344s36ccd5f3sfdd9bf9897d75f70@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/15 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Fri, 2008-08-15 at 10:01 -0400, Tom Lane wrote:
>> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
>> > Random googling shows me that Oracle appears to use a syntax like
>> > name => value
>> > This is actually a feature that I would like to see implemented soonish, so if
>> > anyone has input on the possible syntax consequences, please comment.
>>
>> We've been over this territory before. The problem with "name => value"
>> is that it requires reserving a perfectly good user-defined operator name.
>
> We could declare, that using operator => in function argument expression
> requires parenthesis : func( a => (b => c) means param a with value
> expression (b => c) nad just func((b => c)) means first param with value
> (b=>c)
>

or just use := operator?

select new_person(name := 'Smith') - it's simple and consistent with pl/pgsql.

> the main use of named params is calling functions with default values,
> and giving some params. there I'm more concerned about default args and
> rules for finding right function in presence of functions with both
> multiple args and default values for some.
>
> create function f(a int) ...
>
> create function f(a int, b int default 7)
>
> create function f(text text)
>
> and then calling f(4) - which one would it call
>
> what about f('4')
>
> Of course, we could also have default values without named params, and
> just require keyword DEFAULT where we want default value :)
>
>> "value AS name", on the other hand, accomplishes the same in a more
>> SQL-looking fashion with no new reserved word (since AS is already
>> fully reserved).
>
> would it be more natural / SQL-like to use "value AS name" or "name AS
> value" ?
>

it's question, because SQL wit AS clause don't specify value, it
specifies label.

Regards
Pavel

> -------------
> Hannu
>
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 15:59:23
Message-ID: 14899.1218902363@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> or just use := operator?

You're still commandeering an operator name that wasn't reserved before.
This one doesn't even have the feeble excuse of being Oracle-compatible.

regards, tom lane


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 17:44:38
Message-ID: 200808162044.39442.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Saturday 16 August 2008 09:38:41 Pavel Stehule wrote:
> because you have to write labels, where labels are equal with column
> names. I would to add same comfort like SQL/XML functions.

Just a thought: You might be able to design this in some way to work on top of
named parameter calling. Define a function with variadic arguments and allow
passing arbitrary parameter names. Before you can use that to implement
xmlforest in user space you need to work out the issue of passing arbitrary
argument types. But that is also something that would be interesting for
other purposes.


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 17:52:24
Message-ID: 1218909144.7387.28.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 2008-08-16 at 08:44 +0200, Pavel Stehule wrote:
> Hello

> >> "value AS name", on the other hand, accomplishes the same in a more
> >> SQL-looking fashion with no new reserved word (since AS is already
> >> fully reserved).
> >
> > would it be more natural / SQL-like to use "value AS name" or "name AS
> > value" ?
> >
>
> it's question, because SQL wit AS clause don't specify value, it
> specifies label.

A "label" is the same thing as "variable"/"attribute"/"argument name" in
all programming languages I can think of. Why do you need two kinds of
argument names in postgreSQL ?

maybe you are after something like keyword arguments in python ?

http://docs.python.org/tut/node6.html#SECTION006720000000000000000

keyword arguments are a way of saying that you don't know all variable
names (or "labels" if you prefer) at function defining time and are
going to pass them in when calling.

It's kind of extended variadic argument, only with names and types for
each extra arg.

Of course we could extend this to have shortcut of passing in original
variable or field names automatically, without you having to explicitly
write it down that is fun(name) instead of fun(name=name) but I'm not
sure it is actually a good idea. SQL in general has not been very terse
language.

But I sure would like to have the flexibility of keyword arguments in
PostgreSQL .

> Regards
> Pavel
>
>
> > -------------
> > Hannu
> >
> >
> >


From: Decibel! <decibel(at)decibel(dot)org>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-16 18:09:55
Message-ID: 0097CE73-D249-4452-BB11-2A5C698EDB80@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Aug 15, 2008, at 1:20 PM, Hannu Krosing wrote:
>> "value AS name", on the other hand, accomplishes the same in a more
>> SQL-looking fashion with no new reserved word (since AS is already
>> fully reserved).
>
> would it be more natural / SQL-like to use "value AS name" or "name AS
> value" ?

IMHO, *natural* would be name *something* value, because that's how
every other language I've seen does it.

SQL-like would be value AS name, but I'm not a fan of putting the
value before the name. And I think value AS name will just lead to a
ton of confusion.

Since I think it'd be very unusual to do a => (b => c), I'd vote that
we just go with =>. Anyone trying to do a => b => c should
immediately question if that would work.
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 06:06:43
Message-ID: 162867790808162306r53d57098ic3e98a9d5264f1a0@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/16 Decibel! <decibel(at)decibel(dot)org>:
> On Aug 15, 2008, at 1:20 PM, Hannu Krosing wrote:
>>>
>>> "value AS name", on the other hand, accomplishes the same in a more
>>> SQL-looking fashion with no new reserved word (since AS is already
>>> fully reserved).
>>
>> would it be more natural / SQL-like to use "value AS name" or "name AS
>> value" ?
>
>
> IMHO, *natural* would be name *something* value, because that's how every
> other language I've seen does it.
>
> SQL-like would be value AS name, but I'm not a fan of putting the value
> before the name. And I think value AS name will just lead to a ton of
> confusion.
>
> Since I think it'd be very unusual to do a => (b => c), I'd vote that we
> just go with =>. Anyone trying to do a => b => c should immediately question
> if that would work.

I'll look on this syntax - what is really means for implementation. I
thing, mostly of us prefer this or similar syntax.

Regards
Pavel Stehule

> --
> Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
> Give your computer some brain candy! www.distributed.net Team #1828
>
>
>


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Decibel! <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 11:51:39
Message-ID: 1218973899.9118.5.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2008-08-17 at 08:06 +0200, Pavel Stehule wrote:
> 2008/8/16 Decibel! <decibel(at)decibel(dot)org>:
> > On Aug 15, 2008, at 1:20 PM, Hannu Krosing wrote:
> >>>
> >>> "value AS name", on the other hand, accomplishes the same in a more
> >>> SQL-looking fashion with no new reserved word (since AS is already
> >>> fully reserved).
> >>
> >> would it be more natural / SQL-like to use "value AS name" or "name AS
> >> value" ?
> >
> >
> > IMHO, *natural* would be name *something* value, because that's how every
> > other language I've seen does it.
> >
> > SQL-like would be value AS name, but I'm not a fan of putting the value
> > before the name. And I think value AS name will just lead to a ton of
> > confusion.
> >
> > Since I think it'd be very unusual to do a => (b => c), I'd vote that we
> > just go with =>. Anyone trying to do a => b => c should immediately question
> > if that would work.
>
> I'll look on this syntax - what is really means for implementation. I
> thing, mostly of us prefer this or similar syntax.

Actually the most "natural" syntax to me is just f(name=value) similar
to how UPDATE does it. It has the added benefit of _not_ forcing us to
make a operator reserved (AFAIK "=" can't be used to define new ops)

And I still don't think we need two kinds of names ("argument name" and
"label"). I'd rather see us have the syntax for this be similar to
python's keyword arguments, even though I'm not entirely opposed to
automatically generating the name= part if it comes from existing name
(variable, function argument or column name).

---------------
Hannu


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 15:08:34
Message-ID: 20151.1218985714@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> Actually the most "natural" syntax to me is just f(name=value) similar
> to how UPDATE does it. It has the added benefit of _not_ forcing us to
> make a operator reserved (AFAIK "=" can't be used to define new ops)

*What* are you thinking?

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 15:55:21
Message-ID: 162867790808170855r291c0791hb2f8cedf2c903d70@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sun, 2008-08-17 at 08:06 +0200, Pavel Stehule wrote:
>> 2008/8/16 Decibel! <decibel(at)decibel(dot)org>:
>> > On Aug 15, 2008, at 1:20 PM, Hannu Krosing wrote:
>> >>>
>> >>> "value AS name", on the other hand, accomplishes the same in a more
>> >>> SQL-looking fashion with no new reserved word (since AS is already
>> >>> fully reserved).
>> >>
>> >> would it be more natural / SQL-like to use "value AS name" or "name AS
>> >> value" ?
>> >
>> >
>> > IMHO, *natural* would be name *something* value, because that's how every
>> > other language I've seen does it.
>> >
>> > SQL-like would be value AS name, but I'm not a fan of putting the value
>> > before the name. And I think value AS name will just lead to a ton of
>> > confusion.
>> >
>> > Since I think it'd be very unusual to do a => (b => c), I'd vote that we
>> > just go with =>. Anyone trying to do a => b => c should immediately question
>> > if that would work.
>>
>> I'll look on this syntax - what is really means for implementation. I
>> thing, mostly of us prefer this or similar syntax.
>
> Actually the most "natural" syntax to me is just f(name=value) similar
> to how UPDATE does it. It has the added benefit of _not_ forcing us to
> make a operator reserved (AFAIK "=" can't be used to define new ops)
>
> And I still don't think we need two kinds of names ("argument name" and
> "label"). I'd rather see us have the syntax for this be similar to
> python's keyword arguments, even though I'm not entirely opposed to
> automatically generating the name= part if it comes from existing name
> (variable, function argument or column name).
>

I wouldn't mix together two features - argument name (keyword
argument) and labels. Its two different features.

Regards
Pavel Stehule

> ---------------
> Hannu
>
>
>


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 15:55:59
Message-ID: 1218988559.8075.13.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> > Actually the most "natural" syntax to me is just f(name=value) similar
> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
> > make a operator reserved (AFAIK "=" can't be used to define new ops)
>
> *What* are you thinking?

I think that we could achieve what Pavel was after by allowing one to
define something similar to keyword arguments in python.

maybe allow input RECORD type, which is instantiated at call time by
giving extra arguments to function call:

CREATE FUNCTION f_kw(r record) ....

and then if you call it like this:

SELECT ... f_kw(name='bob', age=7::int)

then function gets as its input a record
which can be accessed in pl/pgsql like

r.name r.age

and if terseness is really appreciated then the it could also be called
like this

SELECT ... f_kw(name, age) from people where name='bob';

which is rewritten to

SELECT ... f_kw(name=name, age=age) from people where name='bob';

not sure if we should allow defining SETOF RECORD and then enable
calling it with

SELECT *
FROM f_kw(
VALUES(name='bob', age=7::int),
VALUES(name='bill', age=42::int
);

or somesuch

------------------
Hannu


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 15:59:56
Message-ID: 162867790808170859kf9a01a7kcd9819cf778e154e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu

it's not possible in plpgsql, because we are not able iterate via record.

Pavel

2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
>> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> > Actually the most "natural" syntax to me is just f(name=value) similar
>> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
>> > make a operator reserved (AFAIK "=" can't be used to define new ops)
>>
>> *What* are you thinking?
>
> I think that we could achieve what Pavel was after by allowing one to
> define something similar to keyword arguments in python.
>
> maybe allow input RECORD type, which is instantiated at call time by
> giving extra arguments to function call:
>
> CREATE FUNCTION f_kw(r record) ....
>
> and then if you call it like this:
>
> SELECT ... f_kw(name='bob', age=7::int)
>
> then function gets as its input a record
> which can be accessed in pl/pgsql like
>
> r.name r.age
>
> and if terseness is really appreciated then the it could also be called
> like this
>
> SELECT ... f_kw(name, age) from people where name='bob';
>
> which is rewritten to
>
> SELECT ... f_kw(name=name, age=age) from people where name='bob';
>
>
> not sure if we should allow defining SETOF RECORD and then enable
> calling it with
>
> SELECT *
> FROM f_kw(
> VALUES(name='bob', age=7::int),
> VALUES(name='bill', age=42::int
> );
>
> or somesuch
>
> ------------------
> Hannu
>
>
>


From: "Asko Oja" <ascoja(at)gmail(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 18:05:27
Message-ID: ecd779860808171105q60df4751m26ffc8946aee7244@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Not able to means not implementable o not implemented ?

On Sun, Aug 17, 2008 at 6:59 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>wrote:

> Hannu
>
> it's not possible inNot able to plpgsql, because we are not able iterate
> via record.
>
> Pavel
>
> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
> >> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> >> > Actually the most "natural" syntax to me is just f(name=value) similar
> >> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
> >> > make a operator reserved (AFAIK "=" can't be used to define new ops)
> >>
> >> *What* are you thinking?
> >
> > I think that we could achieve what Pavel was after by allowing one to
> > define something similar to keyword arguments in python.
> >
> > maybe allow input RECORD type, which is instantiated at call time by
> > giving extra arguments to function call:
> >
> > CREATE FUNCTION f_kw(r record) ....
> >
> > and then if you call it like this:
> >
> > SELECT ... f_kw(name='bob', age=7::int)
> >
> > then function gets as its input a record
> > which can be accessed in pl/pgsql like
> >
> > r.name r.age
> >
> > and if terseness is really appreciated then the it could also be called
> > like this
> >
> > SELECT ... f_kw(name, age) from people where name='bob';
> >
> > which is rewritten to
> >
> > SELECT ... f_kw(name=name, age=age) from people where name='bob';
> >
> >
> > not sure if we should allow defining SETOF RECORD and then enable
> > calling it with
> >
> > SELECT *
> > FROM f_kw(
> > VALUES(name='bob', age=7::int),
> > VALUES(name='bill', age=42::int
> > );
> >
> > or somesuch
> >
> > ------------------
> > Hannu
> >
> >
> >
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Decibel!" <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 18:06:53
Message-ID: 87ljyvwm6a.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:

> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>> On Sun, 2008-08-17 at 08:06 +0200, Pavel Stehule wrote:
>>> 2008/8/16 Decibel! <decibel(at)decibel(dot)org>:
>>> > SQL-like would be value AS name, but I'm not a fan of putting the value
>>> > before the name. And I think value AS name will just lead to a ton of
>>> > confusion.
>>> >
>>> > Since I think it'd be very unusual to do a => (b => c), I'd vote that we
>>> > just go with =>. Anyone trying to do a => b => c should immediately question
>>> > if that would work.
>>>
>>> I'll look on this syntax - what is really means for implementation. I
>>> thing, mostly of us prefer this or similar syntax.
>>
>> Actually the most "natural" syntax to me is just f(name=value) similar
>> to how UPDATE does it. It has the added benefit of _not_ forcing us to
>> make a operator reserved (AFAIK "=" can't be used to define new ops)

This whole thing seems like a ridiculous idea. It's a fancy way of passing an
extra parameter to the function intended to be used for a particular "label"
purpose. Your xml function could just as easily take two functions
f(name,value) instead of using a special spelling for ",".

That it is easily confused with named parameters means there are huge
downsides and no significant up-sides to having this trivial little bit of
syntactic sugar.

To say nothing that using "=>" or anything like that would be just completely
un-SQLish.

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Get trained by Bruce Momjian - ask me about EnterpriseDB's PostgreSQL training!


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Asko Oja" <ascoja(at)gmail(dot)com>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 18:50:45
Message-ID: 162867790808171150x6920767wb683d88c7cb19789@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/17 Asko Oja <ascoja(at)gmail(dot)com>:
> Not able to means not implementable o not implemented ?

Almost not implementable - plpgsql is too static language.

>
> On Sun, Aug 17, 2008 at 6:59 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>>
>> Hannu
>>
>> it's not possible inNot able to plpgsql, because we are not able iterate
>> via record.
>>
>> Pavel
>>
>> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>> > On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
>> >> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> >> > Actually the most "natural" syntax to me is just f(name=value)
>> >> > similar
>> >> > to how UPDATE does it. It has the added benefit of _not_ forcing us
>> >> > to
>> >> > make a operator reserved (AFAIK "=" can't be used to define new ops)
>> >>
>> >> *What* are you thinking?
>> >
>> > I think that we could achieve what Pavel was after by allowing one to
>> > define something similar to keyword arguments in python.
>> >
>> > maybe allow input RECORD type, which is instantiated at call time by
>> > giving extra arguments to function call:
>> >
>> > CREATE FUNCTION f_kw(r record) ....
>> >
>> > and then if you call it like this:
>> >
>> > SELECT ... f_kw(name='bob', age=7::int)
>> >
>> > then function gets as its input a record
>> > which can be accessed in pl/pgsql like
>> >
>> > r.name r.age
>> >
>> > and if terseness is really appreciated then the it could also be called
>> > like this
>> >
>> > SELECT ... f_kw(name, age) from people where name='bob';
>> >
>> > which is rewritten to
>> >
>> > SELECT ... f_kw(name=name, age=age) from people where name='bob';
>> >
>> >
>> > not sure if we should allow defining SETOF RECORD and then enable
>> > calling it with
>> >
>> > SELECT *
>> > FROM f_kw(
>> > VALUES(name='bob', age=7::int),
>> > VALUES(name='bill', age=42::int
>> > );
>> >
>> > or somesuch
>> >
>> > ------------------
>> > Hannu
>> >
>> >
>> >
>>
>> --
>> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-hackers
>
>


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 21:48:22
Message-ID: 1219009702.8075.20.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2008-08-17 at 17:59 +0200, Pavel Stehule wrote:
> Hannu
>
> it's not possible in plpgsql, because we are not able iterate via record.

just add function for iterating over record :)

create or replace function json(r record)
returns varchar as $$
select '[' || array_to_string(
array(
select (getfieldnames(r))[i]|| ':' || getfieldvalue(r,i)
from generate_subscripts(r,1) g(i))
,',') || ']'
$$ language sql immutable strict;

(this is a straight rewrite of your original sample, one can also do it
in a simpler way, with a function returning SETOF (name, value) pairs)

postgres=# select json(name='Zdenek',age=30);
json
----------------------
[name:Zdenek,age:30]
(1 row)

postgres=# select json(name, age) from person;
json
----------------------
[name:Zdenek,age:30]
(1 row)

BTW, json actually requires quoting names/labels, so the answer should
be

["name":"Zdenek","age":"30"]

>
> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
> >> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> >> > Actually the most "natural" syntax to me is just f(name=value) similar
> >> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
> >> > make a operator reserved (AFAIK "=" can't be used to define new ops)
> >>
> >> *What* are you thinking?
> >
> > I think that we could achieve what Pavel was after by allowing one to
> > define something similar to keyword arguments in python.
> >
> > maybe allow input RECORD type, which is instantiated at call time by
> > giving extra arguments to function call:
> >
> > CREATE FUNCTION f_kw(r record) ....
> >
> > and then if you call it like this:
> >
> > SELECT ... f_kw(name='bob', age=7::int)
> >
> > then function gets as its input a record
> > which can be accessed in pl/pgsql like
> >
> > r.name r.age
> >
> > and if terseness is really appreciated then the it could also be called
> > like this
> >
> > SELECT ... f_kw(name, age) from people where name='bob';
> >
> > which is rewritten to
> >
> > SELECT ... f_kw(name=name, age=age) from people where name='bob';
> >
> >
> > not sure if we should allow defining SETOF RECORD and then enable
> > calling it with
> >
> > SELECT *
> > FROM f_kw(
> > VALUES(name='bob', age=7::int),
> > VALUES(name='bill', age=42::int
> > );
> >
> > or somesuch
> >
> > ------------------
> > Hannu
> >
> >
> >
>


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 22:24:59
Message-ID: 603c8f070808171524te28290by24514303f237601e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Actually the most "natural" syntax to me is just f(name=value) similar
> to how UPDATE does it. It has the added benefit of _not_ forcing us to
> make a operator reserved (AFAIK "=" can't be used to define new ops)

The problem with this is that

SELECT foo(a = b)

...is already valid syntax. It means compare a with b and pass the
resulting boolean to foo. I'm almost positive that changing this
would break all kinds of existing code (and probably create a lot of
grammar problems too). It's not an issue with SET because in that
case the "name=" part of the syntax is required rather than optional.

Any other operator you pick is going to have this same problem unless
it's already impossible to use that operator as part of an expression.
For that reason, while I'm not convinced of the value of the feature,
if we're going to support it then ISTM that expr AS label is the way
to go. That also has the advantage of being consistent with the
syntax for table and column aliasing.

...Robert


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-17 23:17:12
Message-ID: 1219015032.8075.34.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2008-08-17 at 18:24 -0400, Robert Haas wrote:
> > Actually the most "natural" syntax to me is just f(name=value) similar
> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
> > make a operator reserved (AFAIK "=" can't be used to define new ops)
>
> The problem with this is that
>
> SELECT foo(a = b)
>
> ...is already valid syntax.

uups, completely forgot dual use of = for both assignment and
comparison.

> It means compare a with b and pass the
> resulting boolean to foo. I'm almost positive that changing this
> would break all kinds of existing code (and probably create a lot of
> grammar problems too). It's not an issue with SET because in that
> case the "name=" part of the syntax is required rather than optional.

Maybe we can do without any "keyword arguments" or "labeled function
params" if we define a way to construct records in-place.

something like

RECORD( 'Zdanek'::text AS name, 22::int AS age); -- like SELECT

or

RECORD( name 'Zdanek'::text, age 22::int); -- like CREATE TABLE/TYPE

or

RECORD(name, age) .... from sometable; -- get values & types from table

?

Then we could pass these records to any PL for processing with minimal
confusion to programmer, and without introducing new concepts like
"variadic argument position labels"

-------------
Hannu


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 00:07:55
Message-ID: 603c8f070808171707lede45d8te5e92e9cce3941a@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> uups, completely forgot dual use of = for both assignment and
> comparison.
>
> Maybe we can do without any "keyword arguments" or "labeled function
> params" if we define a way to construct records in-place.

That sounds a lot cleaner to me.

> something like
> RECORD( 'Zdanek'::text AS name, 22::int AS age); -- like SELECT
> or
> RECORD( name 'Zdanek'::text, age 22::int); -- like CREATE TABLE/TYPE
> or
> RECORD(name, age) .... from sometable; -- get values & types from table

In most cases, you can just do this using SELECT without the need for
any special syntax. For example:

SELECT json(p) FROM person p;
SELECT json(p) FROM (SELECT first_name, last_name FROM person) p;

The only problem is that this doesn't work if you try to put the
select into the attribute list:

SELECT json(select first_name, last_name) FROM person p;
ERROR: syntax error at or near "select"
SELECT json((select first_name, last_name)) FROM person p;
ERROR: subquery must return only one column

Unfortunately this is a pretty common situation, because you might
easily want to do:

SELECT json((select first_name, last_name)), age FROM person p;

...and you are out of luck.

I'm not sure whether the ROW() syntax could possibly be extended to
address this problem. It doesn't seem to help in its present form.

> Then we could pass these records to any PL for processing with minimal
> confusion to programmer, and without introducing new concepts like
> "variadic argument position labels"

Amen.

...Robert


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 06:53:37
Message-ID: 162867790808172353m588c3eafs1e82e6cd8647eb52@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sun, 2008-08-17 at 17:59 +0200, Pavel Stehule wrote:
>> Hannu
>>
>> it's not possible in plpgsql, because we are not able iterate via record.
>
> just add function for iterating over record :)

it's not easy, when iterating should be fast - when record's field has
different types, than isn't possible cache execution plan.

Pavel

>
> create or replace function json(r record)
> returns varchar as $$
> select '[' || array_to_string(
> array(
> select (getfieldnames(r))[i]|| ':' || getfieldvalue(r,i)
> from generate_subscripts(r,1) g(i))
> ,',') || ']'
> $$ language sql immutable strict;
>
> (this is a straight rewrite of your original sample, one can also do it
> in a simpler way, with a function returning SETOF (name, value) pairs)
>
> postgres=# select json(name='Zdenek',age=30);
> json
> ----------------------
> [name:Zdenek,age:30]
> (1 row)
>
> postgres=# select json(name, age) from person;
> json
> ----------------------
> [name:Zdenek,age:30]
> (1 row)
>
> BTW, json actually requires quoting names/labels, so the answer should
> be
>
> ["name":"Zdenek","age":"30"]
>
>
>>
>> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>> > On Sun, 2008-08-17 at 11:08 -0400, Tom Lane wrote:
>> >> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> >> > Actually the most "natural" syntax to me is just f(name=value) similar
>> >> > to how UPDATE does it. It has the added benefit of _not_ forcing us to
>> >> > make a operator reserved (AFAIK "=" can't be used to define new ops)
>> >>
>> >> *What* are you thinking?
>> >
>> > I think that we could achieve what Pavel was after by allowing one to
>> > define something similar to keyword arguments in python.
>> >
>> > maybe allow input RECORD type, which is instantiated at call time by
>> > giving extra arguments to function call:
>> >
>> > CREATE FUNCTION f_kw(r record) ....
>> >
>> > and then if you call it like this:
>> >
>> > SELECT ... f_kw(name='bob', age=7::int)
>> >
>> > then function gets as its input a record
>> > which can be accessed in pl/pgsql like
>> >
>> > r.name r.age
>> >
>> > and if terseness is really appreciated then the it could also be called
>> > like this
>> >
>> > SELECT ... f_kw(name, age) from people where name='bob';
>> >
>> > which is rewritten to
>> >
>> > SELECT ... f_kw(name=name, age=age) from people where name='bob';
>> >
>> >
>> > not sure if we should allow defining SETOF RECORD and then enable
>> > calling it with
>> >
>> > SELECT *
>> > FROM f_kw(
>> > VALUES(name='bob', age=7::int),
>> > VALUES(name='bill', age=42::int
>> > );
>> >
>> > or somesuch
>> >
>> > ------------------
>> > Hannu
>> >
>> >
>> >
>>
>
>


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Hannu Krosing <hannu(at)2ndquadrant(dot)com>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 07:51:03
Message-ID: 200808181051.04541.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Am Saturday, 16. August 2008 schrieb Hannu Krosing:
> A "label" is the same thing as "variable"/"attribute"/"argument name" in
> all  programming languages I can think of. Why do you need two kinds of
> argument names in postgreSQL ?
>
> maybe you are after something like keyword arguments in python ?
>
> http://docs.python.org/tut/node6.html#SECTION006720000000000000000
>
> keyword arguments are a way of saying that you don't know all variable
> names (or "labels" if you prefer) at function defining time and are
> going to pass them in when calling.

I think we are beginning to talk about the same thing. (Meaning you and me --
not sure about the rest. :) )


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: [SPAM?]: Re: proposal sql: labeled function params
Date: 2008-08-18 10:59:50
Message-ID: 1219057190.8075.44.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2008-08-18 at 10:51 +0300, Peter Eisentraut wrote:
> Am Saturday, 16. August 2008 schrieb Hannu Krosing:
> > A "label" is the same thing as "variable"/"attribute"/"argument name" in
> > all programming languages I can think of. Why do you need two kinds of
> > argument names in postgreSQL ?
> >
> > maybe you are after something like keyword arguments in python ?
> >
> > http://docs.python.org/tut/node6.html#SECTION006720000000000000000
> >
> > keyword arguments are a way of saying that you don't know all variable
> > names (or "labels" if you prefer) at function defining time and are
> > going to pass them in when calling.
>
> I think we are beginning to talk about the same thing. (Meaning you and me --
> not sure about the rest. :) )

Yes, I noticed that. Maybe we are onto something ;)

The exact moment I sent my mail away, I received yours.

------------
Hannu


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 10:59:52
Message-ID: 1219057192.8075.46.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2008-08-18 at 08:53 +0200, Pavel Stehule wrote:
> 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > On Sun, 2008-08-17 at 17:59 +0200, Pavel Stehule wrote:
> >> Hannu
> >>
> >> it's not possible in plpgsql, because we are not able iterate via record.
> >
> > just add function for iterating over record :)
>
> it's not easy, when iterating should be fast - when record's field has
> different types, than isn't possible cache execution plan.

the iterator should convert them to some common type like TEXT

------------
Hannu


From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Decibel!" <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 15:19:56
Message-ID: 200808181519.m7IFJu512255@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


Is this a TODO?

---------------------------------------------------------------------------

Hannu Krosing wrote:
> On Mon, 2008-08-18 at 08:53 +0200, Pavel Stehule wrote:
> > 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > > On Sun, 2008-08-17 at 17:59 +0200, Pavel Stehule wrote:
> > >> Hannu
> > >>
> > >> it's not possible in plpgsql, because we are not able iterate via record.
> > >
> > > just add function for iterating over record :)
> >
> > it's not easy, when iterating should be fast - when record's field has
> > different types, than isn't possible cache execution plan.
>
> the iterator should convert them to some common type like TEXT
>
> ------------
> Hannu
>
>
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ If your life is a hard drive, Christ can be your backup. +


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 15:25:03
Message-ID: 1219073103.17156.1.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Mon, 2008-08-18 at 11:19 -0400, Bruce Momjian wrote:
> Is this a TODO?

I don't think we have a TODO yet.

Maybe a TBD :)

> ---------------------------------------------------------------------------
>
> Hannu Krosing wrote:
> > On Mon, 2008-08-18 at 08:53 +0200, Pavel Stehule wrote:
> > > 2008/8/17 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > > > On Sun, 2008-08-17 at 17:59 +0200, Pavel Stehule wrote:
> > > >> Hannu
> > > >>
> > > >> it's not possible in plpgsql, because we are not able iterate via record.
> > > >
> > > > just add function for iterating over record :)
> > >
> > > it's not easy, when iterating should be fast - when record's field has
> > > different types, than isn't possible cache execution plan.
> >
> > the iterator should convert them to some common type like TEXT
> >
> > ------------
> > Hannu
> >
> >
> >
> > --
> > Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> > To make changes to your subscription:
> > http://www.postgresql.org/mailpref/pgsql-hackers
>


From: "Robert Haas" <robertmhaas(at)gmail(dot)com>
To: "Bruce Momjian" <bruce(at)momjian(dot)us>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-18 15:25:57
Message-ID: 603c8f070808180825t2caf2d91sbc426206686bb98e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

There may be a TODO in this thread somewhere, but I think this
particular suggestion has drifted pretty far from the problem that
Pavel was trying to solve.

...Robert

On Mon, Aug 18, 2008 at 11:19 AM, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>
> Is this a TODO?
>
>> > >> it's not possible in plpgsql, because we are not able iterate via record.
>> > >
>> > > just add function for iterating over record :)
>> >
>> > it's not easy, when iterating should be fast - when record's field has
>> > different types, than isn't possible cache execution plan.
>>
>> the iterator should convert them to some common type like TEXT


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Robert Haas" <robertmhaas(at)gmail(dot)com>
Cc: "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-20 10:38:11
Message-ID: 162867790808200338k42d475b6rc3557d68e4aefc55@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

I understand now why Oracle use => symbol for named params. This isn't
used so operator - so implementation is trivial.

postgres=# create function x(a boolean) returns bool as $$select $1$$
language sql;
CREATE FUNCTION
Time: 5,549 ms
postgres=# select x(a => true);
x
---
t
(1 row)

Time: 0,566 ms
postgres=# select x(a => 0 >= 1);
x
---
f
(1 row)

Time: 0,772 ms
postgres=# select x(a => 0 <= 1);
x
---
t
(1 row)

Time: 0,633 ms
postgres=# select x(a => 0 <= 1);

it could live together with labels
postgres=# select x(a => 0 <= 1 as boo);
x
---
t
(1 row)

there are not any conflict. nice (operator => is never used).

I dislike to use AS for named params - it has some unhappy consequences:
a) it merge two features together (named params, labels),
b) when we disable @a, then we should implement only one feature - named params
c) @b isn't compatible with SQL/XML that is implemented now

I don't found any notice about db2 default parameters.

Named params needs different algorithm of searching in pg_proc. There
should be some new problems - like

create function foo(a integer, b integer);
select foo(10,10); -- ok
select foo(a => 10, b =>20); -- ok
select foo(b=>20, a =>20); -- ok
select foo(c=>20, 20); -- unknown fce !!!

Regards
Pavel Stehule

real gram implemenation:
param_list: param
{
$$ = list_make1($1);
}
| param_list ',' param
{
$$ = lappend($1, $3);
}
;

param:
a_expr
{
$$ = $1;
}
| param_name POINTER a_expr
{
$$ = $3;
}
| a_expr AS ColLabel
{
$$ = $1;
}
| param_name POINTER a_expr AS ColLabel
{
$$ = $3;
}
;

lexer
identifier {ident_start}{ident_cont}*

typecast "::"
pointer "=>"


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-20 12:46:22
Message-ID: 27113.1219236382@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> I understand now why Oracle use => symbol for named params. This isn't
> used so operator - so implementation is trivial.

You really didn't understand the objection at all, did you?

The point is not about whether there is any built-in operator named =>.
The point is that people might have created user-defined operators named
that.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-20 13:26:02
Message-ID: 162867790808200626w40350731gc0602099ce3d8e18@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/20 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>> I understand now why Oracle use => symbol for named params. This isn't
>> used so operator - so implementation is trivial.
>
> You really didn't understand the objection at all, did you?
>
> The point is not about whether there is any built-in operator named =>.
> The point is that people might have created user-defined operators named
> that.

I understand well, so only I don't see better solution. Yes, everyone
who used => should have problems, but it is similar with .. new
keywords, etc. Probably easy best syntax doesn't exist :(. I haven't
idea who use => now and how often, and if this feature is possible in
pg, but there are not technical barriers.

regards
Pavel Stehule

>
> regards, tom lane
>


From: "Asko Oja" <ascoja(at)gmail(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-21 20:00:43
Message-ID: ecd779860808211300x157524a7u43146cd357be9438@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Would AS be harder to implement?

select foo(10 AS a, 20 AS b);
select foo(20 AS b, 20 AS a);
select x(0 >= 1 AS a);

other fantasies
select foo(10 a, 20 b);
select foo("a" 10, "b" 20);

regards,
Asko

On Wed, Aug 20, 2008 at 4:26 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>wrote:

> 2008/8/20 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> > "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> >> I understand now why Oracle use => symbol for named params. This isn't
> >> used so operator - so implementation is trivial.
> >
> > You really didn't understand the objection at all, did you?
> >
> > The point is not about whether there is any built-in operator named =>.
> > The point is that people might have created user-defined operators named
> > that.
>
> I understand well, so only I don't see better solution. Yes, everyone
> who used => should have problems, but it is similar with .. new
> keywords, etc. Probably easy best syntax doesn't exist :(. I haven't
> idea who use => now and how often, and if this feature is possible in
> pg, but there are not technical barriers.
>
> regards
> Pavel Stehule
>
>
> >
> > regards, tom lane
> >
>
> --
> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-hackers
>


From: Decibel! <decibel(at)decibel(dot)org>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-22 04:41:30
Message-ID: 46FB9762-82D5-45F0-AAC9-677DD5C96C8D@decibel.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Aug 20, 2008, at 8:26 AM, Pavel Stehule wrote:
> 2008/8/20 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>>> I understand now why Oracle use => symbol for named params. This
>>> isn't
>>> used so operator - so implementation is trivial.
>>
>> You really didn't understand the objection at all, did you?
>>
>> The point is not about whether there is any built-in operator
>> named =>.
>> The point is that people might have created user-defined operators
>> named
>> that.
>
> I understand well, so only I don't see better solution. Yes, everyone
> who used => should have problems, but it is similar with .. new
> keywords, etc. Probably easy best syntax doesn't exist :(. I haven't
> idea who use => now and how often, and if this feature is possible in
> pg, but there are not technical barriers.

How about we poll -general and see what people say? I'll bet Tom a
beer that no one replies saying they've created a => operator (unless
maybe PostGIS uses it).

If we're really worried about it we can have a GUC for a few versions
that turns off named parameter assignment. But I don't think we
should compromise the design on the theory that some folks might be
using that as an operator *and* can't change their application to
wrap it's use in ().
--
Decibel!, aka Jim C. Nasby, Database Architect decibel(at)decibel(dot)org
Give your computer some brain candy! www.distributed.net Team #1828


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Asko Oja" <ascoja(at)gmail(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-22 05:22:44
Message-ID: 162867790808212222ub5324eeq7562339cbc0233df@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/21 Asko Oja <ascoja(at)gmail(dot)com>:
> Would AS be harder to implement?
>
> select foo(10 AS a, 20 AS b);
> select foo(20 AS b, 20 AS a);
> select x(0 >= 1 AS a);
>
> other fantasies
> select foo(10 a, 20 b);
> select foo("a" 10, "b" 20);

no, I have it. Problem is in semantic. There are two features, that
fight about this keyword - named params and labeled params. I don't
thing so using AS for named params is good idea - mainly it's out of
standard (if I should count with SQL/XML) and out of tradition.

regards
Pavel

p.s. => is clean and readable, I thing it's better than space syntax
:)

>
> regards,
> Asko
>
> On Wed, Aug 20, 2008 at 4:26 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
>>
>> 2008/8/20 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> > "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>> >> I understand now why Oracle use => symbol for named params. This isn't
>> >> used so operator - so implementation is trivial.
>> >
>> > You really didn't understand the objection at all, did you?
>> >
>> > The point is not about whether there is any built-in operator named =>.
>> > The point is that people might have created user-defined operators named
>> > that.
>>
>> I understand well, so only I don't see better solution. Yes, everyone
>> who used => should have problems, but it is similar with .. new
>> keywords, etc. Probably easy best syntax doesn't exist :(. I haven't
>> idea who use => now and how often, and if this feature is possible in
>> pg, but there are not technical barriers.
>>
>> regards
>> Pavel Stehule
>>
>>
>> >
>> > regards, tom lane
>> >
>>
>> --
>> Sent via pgsql-hackers mailing list (pgsql-hackers(at)postgresql(dot)org)
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-hackers
>
>


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Decibel! <decibel(at)decibel(dot)org>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-22 19:31:22
Message-ID: 1219433482.7020.5.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, 2008-08-21 at 23:41 -0500, Decibel! wrote:
> On Aug 20, 2008, at 8:26 AM, Pavel Stehule wrote:

> How about we poll -general and see what people say? I'll bet Tom a
> beer that no one replies saying they've created a => operator (unless
> maybe PostGIS uses it).

Does Oracle use => for "labeled function params" or just named
arguments ?

> If we're really worried about it we can have a GUC for a few versions
> that turns off named parameter assignment. But I don't think we
> should compromise the design on the theory that some folks might be
> using that as an operator *and* can't change their application to
> wrap it's use in ().

I still think that better approach is allowing RECORD as input type and
do all the things Pavel proposed with a function that iterates over
record.

--------------
Hannu


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: "Decibel!" <decibel(at)decibel(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-22 20:03:16
Message-ID: 48AF1B84.7090906@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> How about we poll -general and see what people say? I'll bet Tom a
>> beer that no one replies saying they've created a => operator (unless
>> maybe PostGIS uses it).
Hstore uses it:
* text => text - creates hstore type from two text strings

select 'a'=>'b';
?column?
----------
"a"=>"b"

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Feeding results back into select (was: proposal sql: labeled function params)
Date: 2008-08-22 20:46:19
Message-ID: 20080822164619.71bc4e87.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 23 Aug 2008 00:03:16 +0400
Teodor Sigaev <teodor(at)sigaev(dot)ru> wrote:
> select 'a'=>'b';
> ?column?
> ----------
> "a"=>"b"

Branching the topic, I have a question about this. I haven't studied
hstore extensively but this seems like a problem on it's face.
Shouldn't you be able to take the result of a select and pass it back
to a select? I mean, what happens if you do this?

select "a"=>"b";

I suspect that you would get "ERROR: column "a" does not exist" if you
do that. What happens when you try to restore a dump?

I ran into a similar issue with my chkpass type (see contrib) where the
string inserted into the field is stored encrypted with functions to
test for equality basically like the Unix password model works. If I
just displayed raw strings then a dump and reload would have trashed
all the passwords by re-encrypting them. What I did was to make a
special case on input. If the string started with ':' then I strip
that character and insert the string unchanged. Then I changed the
output to prepend the ':'. Now dump and reload work.

Just curious.

--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Teodor Sigaev" <teodor(at)sigaev(dot)ru>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 06:20:44
Message-ID: 162867790808222320m6f341d07jc311da29bdb2ea8c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/22 Teodor Sigaev <teodor(at)sigaev(dot)ru>:
>>> How about we poll -general and see what people say? I'll bet Tom a beer
>>> that no one replies saying they've created a => operator (unless maybe
>>> PostGIS uses it).
>
> Hstore uses it:
> * text => text - creates hstore type from two text strings
>
> select 'a'=>'b';
> ?column?
> ----------
> "a"=>"b"
>
>

we should to have flag (or names are in pg_proc already), when
function allows named params -etc lot of system functions doesn't
named params. So everywhere where function hasn't defined names, then
=> symbol should by transformed to => operator.

???
Pavel

Pavel

> --
> Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
> WWW: http://www.sigaev.ru/
>


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 06:21:39
Message-ID: 162867790808222321q7ddc7a89s1a213c69a7e8373e@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/22 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Thu, 2008-08-21 at 23:41 -0500, Decibel! wrote:
>> On Aug 20, 2008, at 8:26 AM, Pavel Stehule wrote:
>
>> How about we poll -general and see what people say? I'll bet Tom a
>> beer that no one replies saying they've created a => operator (unless
>> maybe PostGIS uses it).
>
> Does Oracle use => for "labeled function params" or just named
> arguments ?
>

Oracle use it for named arguments - what I know, similar it doesn't
allow functionality as labeled params publicly - SQL/XML use it.

>> If we're really worried about it we can have a GUC for a few versions
>> that turns off named parameter assignment. But I don't think we
>> should compromise the design on the theory that some folks might be
>> using that as an operator *and* can't change their application to
>> wrap it's use in ().
>
> I still think that better approach is allowing RECORD as input type and
> do all the things Pavel proposed with a function that iterates over
> record.
>

record or hash table - it's implementation - second step. We have to
find syntax and semantic now.

Pavel

> --------------
> Hannu
>
>
>


From: Teodor Sigaev <teodor(at)sigaev(dot)ru>
To: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Feeding results back into select
Date: 2008-08-23 10:04:30
Message-ID: 48AFE0AE.7060300@sigaev.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

>> select 'a'=>'b';
>> ?column?
>> ----------
>> "a"=>"b"

>
> Branching the topic, I have a question about this. I haven't studied
> hstore extensively but this seems like a problem on it's face.
> Shouldn't you be able to take the result of a select and pass it back
> to a select? I mean, what happens if you do this?
>

"a"=>"b" is a value of hstore type, so query should be:
select '"a"=>"b"'::hstore;

" character was chosen to simplify escaping,

> I ran into a similar issue with my chkpass type (see contrib) where the
> string inserted into the field is stored encrypted with functions to
> test for equality basically like the Unix password model works. If I
> just displayed raw strings then a dump and reload would have trashed
> all the passwords by re-encrypting them. What I did was to make a
> special case on input. If the string started with ':' then I strip
> that character and insert the string unchanged. Then I changed the
> output to prepend the ':'. Now dump and reload work.

I see, but your problem is that password is one-way encrypted, so, you
definitely need to distinguish already encrypted strings. Hstore hasn't that
problem.

--
Teodor Sigaev E-mail: teodor(at)sigaev(dot)ru
WWW: http://www.sigaev.ru/


From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Decibel! <decibel(at)decibel(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 12:35:34
Message-ID: 200808231535.35761.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Friday 22 August 2008 07:41:30 Decibel! wrote:
> If we're really worried about it we can have a GUC for a few versions  
> that turns off named parameter assignment. But I don't think we  
> should compromise the design on the theory that some folks might be  
> using that as an operator *and* can't change their application to  
> wrap it's use in ().

Even if that were a reasonable strategy, you can't use GUC parameters to alter
parser behavior.


From: "D'Arcy J(dot)M(dot) Cain" <darcy(at)druid(dot)net>
To: Teodor Sigaev <teodor(at)sigaev(dot)ru>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Feeding results back into select
Date: 2008-08-23 12:40:20
Message-ID: 20080823084020.16e8ebe4.darcy@druid.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 23 Aug 2008 14:04:30 +0400
Teodor Sigaev <teodor(at)sigaev(dot)ru> wrote:
> >> select 'a'=>'b';
> >> ?column?
> >> ----------
> >> "a"=>"b"
> "a"=>"b" is a value of hstore type, so query should be:
> select '"a"=>"b"'::hstore;

Of course. Now that I understand it's blindingly obvious that the
double quotes above are part of the string and the insert would be;
INSERT INTO table (hfield) VALUES ('"a"=>"b"');

> " character was chosen to simplify escaping,

To prevent;
INSERT INTO table (hfield) VALUES ('''a''=>''b''');

I guess my brain was pointed elsewhere when I asked. Thanks for not
treating me like an idiot. :-)

--
D'Arcy J.M. Cain <darcy(at)druid(dot)net> | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Peter Eisentraut" <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 15:50:48
Message-ID: 162867790808230850h226b90a3gc38301498b39ed8b@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/23 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> On Friday 22 August 2008 07:41:30 Decibel! wrote:
>> If we're really worried about it we can have a GUC for a few versions
>> that turns off named parameter assignment. But I don't think we
>> should compromise the design on the theory that some folks might be
>> using that as an operator *and* can't change their application to
>> wrap it's use in ().
>
> Even if that were a reasonable strategy, you can't use GUC parameters to alter
> parser behavior.
>

I thing, so it's possible - in this case. We should transform named
params to expr after syntax analyze.

Pavel


From: Gregory Stark <stark(at)enterprisedb(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>, "Decibel!" <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 16:08:25
Message-ID: 87myj3pvd2.fsf@oxford.xeocode.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:

> Hello
>
> 2008/8/23 Peter Eisentraut <peter_e(at)gmx(dot)net>:
>> On Friday 22 August 2008 07:41:30 Decibel! wrote:
>>> If we're really worried about it we can have a GUC for a few versions
>>> that turns off named parameter assignment. But I don't think we
>>> should compromise the design on the theory that some folks might be
>>> using that as an operator *and* can't change their application to
>>> wrap it's use in ().
>>
>> Even if that were a reasonable strategy, you can't use GUC parameters to alter
>> parser behavior.
>
> I thing, so it's possible - in this case. We should transform named
> params to expr after syntax analyze.

So for a bit of useless syntactic sugar we should introduce conflicts with
named parameters, conflicts with operators, introduce an un-sqlish syntax and
remove a feature users have already made use of and introduce backwards
compatibility issues for those users?

At any point in this discussion has anyone explained why these labels would
actually be a good idea?

--
Gregory Stark
EnterpriseDB http://www.enterprisedb.com
Ask me about EnterpriseDB's 24x7 Postgres support!


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 16:15:05
Message-ID: 3976.1219508105@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> I thing, so it's possible - in this case. We should transform named
> params to expr after syntax analyze.

You're going to have a hard time making parentheses affect the behavior
if you do it that way.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 19:13:09
Message-ID: 162867790808231213m67343368o3cf7bcd89c1730eb@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/23 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>> I thing, so it's possible - in this case. We should transform named
>> params to expr after syntax analyze.
>
> You're going to have a hard time making parentheses affect the behavior
> if you do it that way.
>
> regards, tom lane
>

I don't prefer this way
regards
Pavel Stehule


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Gregory Stark" <stark(at)enterprisedb(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 19:19:26
Message-ID: 162867790808231219v2a7c7259q347dc0ac404d485f@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> So for a bit of useless syntactic sugar we should introduce conflicts with
> named parameters, conflicts with operators, introduce an un-sqlish syntax and
> remove a feature users have already made use of and introduce backwards
> compatibility issues for those users?
>
we talk only about "=>" symbol. What I googled, I never to find any
database that use AS for named params, and I don't really to create
next proprietary syntax (I would not to wait to ANSI). AS is usable,
but I don't think so it is good idea - it change sense of AS keyword
in SQL.

Oracle: fce (param => expr)
MSSQL: fce @param = expr
Firebird 2.0 allows defaults, but doesn't support named params

> At any point in this discussion has anyone explained why these labels would
> actually be a good idea?
>

it's allows smart libraries like SQL/XML
regards
Pavel Stehule

> --
> Gregory Stark
> EnterpriseDB http://www.enterprisedb.com
> Ask me about EnterpriseDB's 24x7 Postgres support!
>


From: "Greg Stark" <greg(dot)stark(at)enterprisedb(dot)com>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Peter Eisentraut" <peter_e(at)gmx(dot)net>, <pgsql-hackers(at)postgresql(dot)org>, "Decibel!" <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 19:33:58
Message-ID: 3819879A-7495-4E6D-9552-58222371430D@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers


>>
>> At any point in this discussion has anyone explained why these
>> labels would
>> actually be a good idea?
>>
>
> it's allows smart libraries like SQL/XML

You could always just pass the label as an additional parameter. Which
is all this would be syntactic sugar for anyways. So it doesn't
"allow" such libraries it just let users type foo(bar=>'baz') instead
of foo('bar','baz'). Not much gain for all this pain.


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Decibel! <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 19:50:08
Message-ID: 1219521008.26201.2.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
> Hello
>
> 2008/8/22 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> > On Thu, 2008-08-21 at 23:41 -0500, Decibel! wrote:
> >> On Aug 20, 2008, at 8:26 AM, Pavel Stehule wrote:
> >
> >> How about we poll -general and see what people say? I'll bet Tom a
> >> beer that no one replies saying they've created a => operator (unless
> >> maybe PostGIS uses it).
> >
> > Does Oracle use => for "labeled function params" or just named
> > arguments ?
> >
>
> Oracle use it for named arguments - what I know, similar it doesn't
> allow functionality as labeled params publicly - SQL/XML use it.
>
> >> If we're really worried about it we can have a GUC for a few versions
> >> that turns off named parameter assignment. But I don't think we
> >> should compromise the design on the theory that some folks might be
> >> using that as an operator *and* can't change their application to
> >> wrap it's use in ().
> >
> > I still think that better approach is allowing RECORD as input type and
> > do all the things Pavel proposed with a function that iterates over
> > record.
> >
>
> record or hash table - it's implementation - second step. We have to
> find syntax and semantic now.

Why not just use some standard record syntax, like

SELECT(value::type name, ...)

or perhaps some extended ROW() or VALUES() syntax ?

Like this :
SELECT * FROM FUNC(SELECT(value::type name, ...) AS r);

-----------------
Hannu


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Decibel! <decibel(at)decibel(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 21:43:42
Message-ID: 8618.1219527822@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
>> record or hash table - it's implementation - second step. We have to
>> find syntax and semantic now.

> Why not just use some standard record syntax, like
> SELECT(value::type name, ...)

Yeah, that's one way. It also strikes me that hstore itself provides a
usable solution to this problem, though only for simple-string values.
That is, you could do something like

create function myfunc(hstore) returns ...

select myfunc('tag1' => '42' || 'tag2' => 'foobar' || ...);

Or, with the new variadic function support,

create function myfunc(variadic hstore[]) returns ...

select myfunc('tag1' => '42', 'tag2' => 'foobar', ...);

which is just a couple of quote marks away from the syntax Pavel
wants.

regards, tom lane


From: daveg <daveg(at)sonic(dot)net>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Hannu Krosing <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-23 22:48:35
Message-ID: 20080823224835.GS28154@sonic.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sat, Aug 23, 2008 at 05:08:25PM +0100, Gregory Stark wrote:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>
> > Hello
> >
> > 2008/8/23 Peter Eisentraut <peter_e(at)gmx(dot)net>:
> >> On Friday 22 August 2008 07:41:30 Decibel! wrote:
> >>> If we're really worried about it we can have a GUC for a few versions
> >>> that turns off named parameter assignment. But I don't think we
> >>> should compromise the design on the theory that some folks might be
> >>> using that as an operator *and* can't change their application to
> >>> wrap it's use in ().
> >>
> >> Even if that were a reasonable strategy, you can't use GUC parameters to alter
> >> parser behavior.
> >
> > I thing, so it's possible - in this case. We should transform named
> > params to expr after syntax analyze.
>
> So for a bit of useless syntactic sugar we should introduce conflicts with
> named parameters, conflicts with operators, introduce an un-sqlish syntax and
> remove a feature users have already made use of and introduce backwards
> compatibility issues for those users?
>
> At any point in this discussion has anyone explained why these labels would
> actually be a good idea?

I was missing that too. What is this for that makes it so compelling?

-dg

--
David Gould daveg(at)sonic(dot)net 510 536 1443 510 282 0869
If simplicity worked, the world would be overrun with insects.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 05:38:09
Message-ID: 162867790808232238x6a2ef549l4500838da101426c@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/23 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
>> Hello
>>
>> 2008/8/22 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>> > On Thu, 2008-08-21 at 23:41 -0500, Decibel! wrote:
>> >> On Aug 20, 2008, at 8:26 AM, Pavel Stehule wrote:
>> >
>> >> How about we poll -general and see what people say? I'll bet Tom a
>> >> beer that no one replies saying they've created a => operator (unless
>> >> maybe PostGIS uses it).
>> >
>> > Does Oracle use => for "labeled function params" or just named
>> > arguments ?
>> >
>>
>> Oracle use it for named arguments - what I know, similar it doesn't
>> allow functionality as labeled params publicly - SQL/XML use it.
>>
>> >> If we're really worried about it we can have a GUC for a few versions
>> >> that turns off named parameter assignment. But I don't think we
>> >> should compromise the design on the theory that some folks might be
>> >> using that as an operator *and* can't change their application to
>> >> wrap it's use in ().
>> >
>> > I still think that better approach is allowing RECORD as input type and
>> > do all the things Pavel proposed with a function that iterates over
>> > record.
>> >
>>
>> record or hash table - it's implementation - second step. We have to
>> find syntax and semantic now.
>
> Why not just use some standard record syntax, like
>
> SELECT(value::type name, ...)
>
> or perhaps some extended ROW() or VALUES() syntax ?
>
> Like this :
> SELECT * FROM FUNC(SELECT(value::type name, ...) AS r);
>

do you thing, so is it simpler?

Pavel

> -----------------
> Hannu
>
>
>


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: daveg <daveg(at)sonic(dot)net>
Cc: "Gregory Stark" <stark(at)enterprisedb(dot)com>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org, Decibel! <decibel(at)decibel(dot)org>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 05:59:46
Message-ID: 162867790808232259j74359262jbaea7ded8b27add8@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/24 daveg <daveg(at)sonic(dot)net>:
> On Sat, Aug 23, 2008 at 05:08:25PM +0100, Gregory Stark wrote:
>> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>>
>> > Hello
>> >
>> > 2008/8/23 Peter Eisentraut <peter_e(at)gmx(dot)net>:
>> >> On Friday 22 August 2008 07:41:30 Decibel! wrote:
>> >>> If we're really worried about it we can have a GUC for a few versions
>> >>> that turns off named parameter assignment. But I don't think we
>> >>> should compromise the design on the theory that some folks might be
>> >>> using that as an operator *and* can't change their application to
>> >>> wrap it's use in ().
>> >>
>> >> Even if that were a reasonable strategy, you can't use GUC parameters to alter
>> >> parser behavior.
>> >
>> > I thing, so it's possible - in this case. We should transform named
>> > params to expr after syntax analyze.
>>
>> So for a bit of useless syntactic sugar we should introduce conflicts with
>> named parameters, conflicts with operators, introduce an un-sqlish syntax and
>> remove a feature users have already made use of and introduce backwards
>> compatibility issues for those users?
>>
>> At any point in this discussion has anyone explained why these labels would
>> actually be a good idea?
>
> I was missing that too. What is this for that makes it so compelling?

We are talking about two features (or three).

1. Named params (and defaults for params) - allows call function with
less params or with params in different order. - default parameters
allows decrease size of libraries (number of functions). Using default
without named params isn't comfortable (Firebird 2 do it), so we would
named params - named params specifies "some param has value ...",
developer shouldn't specify all params. sure - this functionality is
syntactic sugar and are not necessary - it only increase developer's
comfort.

2. Labeled params - put some knowledge (labels) about used params into
function. This is usable for mainly for serialization and dump
function (typical real case is SQL/XML). Other case are custom
functions in MySQL -
http://www.mysqludf.org/lib_mysqludf_json/index.php , sure - this
functionality is syntactic sugar and are not necessary - it only
increase developer's comfort. Labels params mean "for this value use
label". It same as standard keyword "AS" do it. Labeled params allows
explicit labels or implicit labels (column names).

Regards
Pavel Stehule

>
> -dg
>
>
> --
> David Gould daveg(at)sonic(dot)net 510 536 1443 510 282 0869
> If simplicity worked, the world would be overrun with insects.
>


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 06:05:00
Message-ID: 162867790808232305t51219dccq56b941267bf5de15@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/23 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
>>> record or hash table - it's implementation - second step. We have to
>>> find syntax and semantic now.
>
>> Why not just use some standard record syntax, like
>> SELECT(value::type name, ...)
>
> Yeah, that's one way. It also strikes me that hstore itself provides a
> usable solution to this problem, though only for simple-string values.
> That is, you could do something like
>
> create function myfunc(hstore) returns ...
>
> select myfunc('tag1' => '42' || 'tag2' => 'foobar' || ...);
>
> Or, with the new variadic function support,
>
> create function myfunc(variadic hstore[]) returns ...
>
> select myfunc('tag1' => '42', 'tag2' => 'foobar', ...);
>
> which is just a couple of quote marks away from the syntax Pavel
> wants.
>

it's not far. I am only doesn't know if is it labeled params or named
params :). Using hstore is usable, but I dislike it. There is small
overhead and would to use named params for classic functions - with
different types and fixed count of params. I am thinking so first step
is implementation of defaults without named params like firebird. It's
less controversy.

regards
Pavel Stehule

> regards, tom lane
>


From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 07:52:07
Message-ID: 1219564327.26201.13.camel@huvostro
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, 2008-08-24 at 08:05 +0200, Pavel Stehule wrote:
> 2008/8/23 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> > Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
> >> On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
> >>> record or hash table - it's implementation - second step. We have to
> >>> find syntax and semantic now.
> >
> >> Why not just use some standard record syntax, like
> >> SELECT(value::type name, ...)
> >
> > Yeah, that's one way. It also strikes me that hstore itself provides a
> > usable solution to this problem, though only for simple-string values.
> > That is, you could do something like
> >
> > create function myfunc(hstore) returns ...
> >
> > select myfunc('tag1' => '42' || 'tag2' => 'foobar' || ...);
> >
> > Or, with the new variadic function support,
> >
> > create function myfunc(variadic hstore[]) returns ...
> >
> > select myfunc('tag1' => '42', 'tag2' => 'foobar', ...);
> >
> > which is just a couple of quote marks away from the syntax Pavel
> > wants.
> >
>
> it's not far. I am only doesn't know if is it labeled params or named
> params :).

This is "labeled params", or rather variadic hstore. done this way, it
has added benefit over single hstore param, that "key" or "label" can be
repeated:

select myfunc('name' => 'bob', 'age'=>'42', 'name' => 'bill', ...);

same as

select myfunc2(select('bob' as name, 42 as age, 'bill' as name, ...));

> Using hstore is usable, but I dislike it. There is small
> overhead and would to use named params for classic functions - with
> different types and fixed count of params. I am thinking so first step
> is implementation of defaults without named params like firebird. It's
> less controversy.

-------------------
Hannu


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 08:13:34
Message-ID: 162867790808240113i7986c634g60a01bffcec50c76@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/24 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sun, 2008-08-24 at 08:05 +0200, Pavel Stehule wrote:
>> 2008/8/23 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
>> > Hannu Krosing <hannu(at)2ndQuadrant(dot)com> writes:
>> >> On Sat, 2008-08-23 at 08:21 +0200, Pavel Stehule wrote:
>> >>> record or hash table - it's implementation - second step. We have to
>> >>> find syntax and semantic now.
>> >
>> >> Why not just use some standard record syntax, like
>> >> SELECT(value::type name, ...)
>> >
>> > Yeah, that's one way. It also strikes me that hstore itself provides a
>> > usable solution to this problem, though only for simple-string values.
>> > That is, you could do something like
>> >
>> > create function myfunc(hstore) returns ...
>> >
>> > select myfunc('tag1' => '42' || 'tag2' => 'foobar' || ...);
>> >
>> > Or, with the new variadic function support,
>> >
>> > create function myfunc(variadic hstore[]) returns ...
>> >
>> > select myfunc('tag1' => '42', 'tag2' => 'foobar', ...);
>> >
>> > which is just a couple of quote marks away from the syntax Pavel
>> > wants.
>> >
>>
>> it's not far. I am only doesn't know if is it labeled params or named
>> params :).
>
> This is "labeled params", or rather variadic hstore. done this way, it
> has added benefit over single hstore param, that "key" or "label" can be
> repeated:
>
> select myfunc('name' => 'bob', 'age'=>'42', 'name' => 'bill', ...);
>
> same as
>
> select myfunc2(select('bob' as name, 42 as age, 'bill' as name, ...));
>

and actually, how far we are from original proposal

select myfunc(name => 'bob', age => 42 ...

this syntax is most cleaner, and doesn't need bigger changes in
parser, zero changes in PL

regards
Pavel

>> Using hstore is usable, but I dislike it. There is small
>> overhead and would to use named params for classic functions - with
>> different types and fixed count of params. I am thinking so first step
>> is implementation of defaults without named params like firebird. It's
>> less controversy.
>
> -------------------
> Hannu
>
>
>


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 16:00:01
Message-ID: 23099.1219593601@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
> 2008/8/23 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>> Why not just use some standard record syntax, like

> do you thing, so is it simpler?

It's not about being "simpler", it's about pointing out that there are
ways to do what you need without creating compatibility problems and
without commandeering syntax that, if we were going to commandeer it,
would be far better used for named params.

IMHO, the use-case for labeled parameters is simply much too narrow
to justify giving them special syntax if there is any possible way
to avoid it. We have now seen a couple of ways to do it without
new syntax, at the cost of a few more lines inside the called function
to examine its arguments. But the use-cases you've suggested involve
functions that are complicated enough that that's not going to be any
big deal.

So I feel that the proposal for labeled parameters as such is dead
in the water, and that the only usefulness this thread has had is
(re-) exploring the syntactic alternatives available for named params.

regards, tom lane


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 17:43:23
Message-ID: 162867790808241043v4969e8e3j4fc109ac31097cb3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

2008/8/24 Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com> writes:
>> 2008/8/23 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
>>> Why not just use some standard record syntax, like
>
>> do you thing, so is it simpler?
>
> It's not about being "simpler", it's about pointing out that there are
> ways to do what you need without creating compatibility problems and
> without commandeering syntax that, if we were going to commandeer it,
> would be far better used for named params.
>
> IMHO, the use-case for labeled parameters is simply much too narrow
> to justify giving them special syntax if there is any possible way
> to avoid it. We have now seen a couple of ways to do it without
> new syntax, at the cost of a few more lines inside the called function
> to examine its arguments. But the use-cases you've suggested involve
> functions that are complicated enough that that's not going to be any
> big deal.
>
> So I feel that the proposal for labeled parameters as such is dead
> in the water, and that the only usefulness this thread has had is
> (re-) exploring the syntactic alternatives available for named params.

I feel it too.

Regards
Pavel Stehule

>
> regards, tom lane
>


From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Hannu Krosing <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-24 18:32:36
Message-ID: 20080824183236.GB30960@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Sun, Aug 24, 2008 at 12:00:01PM -0400, Tom Lane wrote:
> So I feel that the proposal for labeled parameters as such is dead
> in the water, and that the only usefulness this thread has had is
> (re-) exploring the syntactic alternatives available for named params.

FWIW, I think the way that python manages named and labelled params in
a single calling syntax fairly straightforward.

http://docs.python.org/tut/node6.html#SECTION006720000000000000000

Have a ncie day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Please line up in a tree and maintain the heap invariant while
> boarding. Thank you for flying nlogn airlines.


From: "Pavel Stehule" <pavel(dot)stehule(at)gmail(dot)com>
To: "Martijn van Oosterhout" <kleptog(at)svana(dot)org>
Cc: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>, "Hannu Krosing" <hannu(at)2ndquadrant(dot)com>, Decibel! <decibel(at)decibel(dot)org>, "Robert Haas" <robertmhaas(at)gmail(dot)com>, "Bruce Momjian" <bruce(at)momjian(dot)us>, "Peter Eisentraut" <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: proposal sql: labeled function params
Date: 2008-08-25 07:06:18
Message-ID: 162867790808250006q18dbda8vfd9a5c1e724176ac@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hello

2008/8/24 Martijn van Oosterhout <kleptog(at)svana(dot)org>:
> On Sun, Aug 24, 2008 at 12:00:01PM -0400, Tom Lane wrote:
>> So I feel that the proposal for labeled parameters as such is dead
>> in the water, and that the only usefulness this thread has had is
>> (re-) exploring the syntactic alternatives available for named params.
>
> FWIW, I think the way that python manages named and labelled params in
> a single calling syntax fairly straightforward.
>
> http://docs.python.org/tut/node6.html#SECTION006720000000000000000
>

I will work on default params first and I return to named params later.

regards
Pavel

> Have a ncie day,
> --
> Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
>> Please line up in a tree and maintain the heap invariant while
>> boarding. Thank you for flying nlogn airlines.
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
>
> iD8DBQFIsalEIB7bNG8LQkwRAu1RAJ0TM9/JMUXZI/A+EtNeKp1KHku4OACfQjVa
> QLr4uM/tzgc2y3lodMi2EnU=
> =OSzx
> -----END PGP SIGNATURE-----
>
>