Re: RfD: more powerful "any" types

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Hannu Krosing <hannu(at)2ndquadrant(dot)com>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Alvaro Herrera <alvherre(at)commandprompt(dot)com>, "David E(dot) Wheeler" <david(at)kineticode(dot)com>, Peter Eisentraut <peter_e(at)gmx(dot)net>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: RfD: more powerful "any" types
Date: 2009-09-14 05:34:59
Message-ID: 162867790909132234v728f14c6jb33678b1aba51479@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2009/9/13 Hannu Krosing <hannu(at)2ndquadrant(dot)com>:
> On Sun, 2009-09-13 at 21:50 +0200, Pavel Stehule wrote:
>> Hello
>>
>> >
>> > ANY [TYPE] and SAME AS [TYPE OF] are syntactic sugar indeed, but they
>> > are much more SQL-like than needing to write "any" or anyelement(n) as
>> > argument type or return type
>> >
>>
>> I looked on possibilities in gram.y and I thing, type identifiers
>>
>> "ANY TYPE" is possible without any problems (this should be synonym for "any"),
>> "SAME AS" needs add "same" keyword to col_name_keywords , i.e. "same"
>> is prohibited for function names - it should be a problem

I afraid so this technique isn't allowed in SQL parser, or is i

>>
>> regards
>> Pavel Stehule
>>
>> I found so pgparser provide some ref type syntax via % symbol. So we
>> can use following syntax:
>>
>> CREATE OR REPLACE FUNCTION foo(a ANY TYPE, b a%TYPE)
>> RETURNS a%TYPE ...
>>
>> It is not pretty like SAME AS, but I am sure, so this is doable
>> (parser knows it now)
>>
>> any other ideas?
>
> Hmm, maybe try to make lexer recognize "SAME AS" as one token and then
> deal with other cases of 'name AS' ?

I afraid so this technique isn't allowed in SQL parser, or is it?

>
> Or make the syntax a little uglier,
>
> CREATE OR REPLACE FUNCTION foo(a ANY TYPE, b TYPE OF a)
>
> CREATE OR REPLACE FUNCTION foo(ANY TYPE, TYPE OF $1)

TYPE OF generate shift/reduce too :(

Pavel

>
>
> and maybe try
>
> CREATE OR REPLACE FUNCTION foo(a ANY TYPE, b TYPE OF a)
> RETURNS ARRAY OF TYPE OF a
>
> instead of
>
> CREATE OR REPLACE FUNCTION foo(a anyelement, b anyelement)
> RETURNS anyarray
>
>>
>> regards
>> Pavel Stehule
>
>
> --
> Hannu Krosing   http://www.2ndQuadrant.com
> PostgreSQL Scalability and Availability
>   Services, Consulting and Training
>
>
>

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-09-14 05:57:29 Re: Why does LOG have higher priority than ERROR and WARNING?
Previous Message Pavel Stehule 2009-09-14 05:22:19 Re: [PATCH] 8.5 plpgsql change for named notation: treat word following AS keyword as label v3