Re: dblink: add polymorphic functions.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Joe Conway <mail(at)joeconway(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, Corey Huinker <corey(dot)huinker(at)gmail(dot)com>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-hackers(at)postgresql(dot)org>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Subject: Re: dblink: add polymorphic functions.
Date: 2015-07-30 02:58:12
Message-ID: 31530.1438225092@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Joe Conway <mail(at)joeconway(dot)com> writes:
> On 07/29/2015 05:13 PM, Tom Lane wrote:
>> What's possibly more palatable is to introduce some other special
>> notation for "obtain the type of this expression at parse time".
>> I'm thinking for example about
>>
>> SELECT x::pg_typeof(some_expression) FROM ...

> You think this could be made to work?

> SELECT x::TYPE OF(some_expression) FROM ...

Hmmm ... that looks kind of nice, but a quick experiment with
bison says it's ambiguous. I tried this just as proof-of-concept:

*** src/backend/parser/gram.y~ Fri Jul 24 21:40:02 2015
--- src/backend/parser/gram.y Wed Jul 29 22:45:04 2015
*************** GenericType:
*** 11065,11070 ****
--- 11065,11074 ----
$$->typmods = $3;
$$->location = @1;
}
+ | TYPE_P OF '(' a_expr ')'
+ {
+ $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
+ }
;

opt_type_modifiers: '(' expr_list ')' { $$ = $2; }

and got a shift/reduce conflict. I'm not quite sure why, but since OF
is also not a reserved keyword, it's likely that this is unfixable.
In fact, I also tried "TYPE_P FROM", not because that is especially
great syntax but because FROM *is* fully reserved, and that did not
work either. So this isn't looking like a promising line of thought.

We can definitely do

SELECT x::any_single_unreserved_word(some_expression) FROM ...

because that's actually not something the grammar needs to distinguish
from type-with-a-typmod; we can deal with the special case in
LookupTypeName. It's just a matter of picking a word people like.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-07-30 03:17:42 Re: The real reason why TAP testing isn't ready for prime time
Previous Message Michael Paquier 2015-07-30 02:57:13 Re: The real reason why TAP testing isn't ready for prime time