Re: dblink: add polymorphic functions.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Joe Conway <mail(at)joeconway(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 00:13:41
Message-ID: 26830.1438215221@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> Well, it would depend on how we fixed %TYPE, but my thought is that
> we should teach the core parser to accept variable%TYPE anywhere that
> a suitable "variable" is in scope. The core already allows related
> syntaxes in some utility commands, but not within DML commands.

I poked at this a little bit, and concluded that it's probably impossible
to do it exactly like that, at least not in a backward-compatible way.
The difficulty is that TYPE is an unreserved keyword, and can therefore
be a column name, while of course '%' is a valid operator. So for example

SELECT x::int%type FROM ...

currently means "cast column x to integer and then modulo it by column
type". AFAICS there's no way to introduce %TYPE into the :: cast syntax
without breaking this interpretation.

I suppose that we could dodge this ambiguity by allowing %TYPE only in the
CAST() notation, but this would be the first time that CAST and :: had any
differences in how the type name could be spelled, and that's not a nice
inconsistency to introduce either.

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 ...

Maybe it would be too confusing to overload "pg_typeof" this way,
in which case we could choose some other name. Aside from that
consideration, this approach would have the effect of preventing
"pg_typeof" from being used as an actual type name, or at least from
being used as a type name that can have typmod, but that doesn't seem
like a huge drawback.

This way would have the rather nice property that some_expression could
actually be any parseable expression, not merely a qualified variable
name (which I think is the only case that we'd have had any hope of
supporting with %TYPE).

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Joe Conway 2015-07-30 00:20:22 Re: dblink: add polymorphic functions.
Previous Message Michael Paquier 2015-07-29 23:50:19 Re: Supporting TAP tests with MSVC and Windows