Re: RfD: more powerful "any" types

From: Hannu Krosing <hannu(at)2ndQuadrant(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(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-13 20:37:49
Message-ID: 1252874269.3868.4.camel@hvost1700
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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
>
> 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' ?

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)

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Peter Eisentraut 2009-09-13 21:10:44 Rough draft: easier translation of psql help
Previous Message Peter Eisentraut 2009-09-13 19:54:21 Re: autovacuum_max_workers docs