Tom Lane wrote:
> Joe Conway <m...@joeconway.com> writes:
> > What about just TYPE then?
> 
> >     SELECT x::TYPE(some_expression) FROM ...
> >     SELECT CAST (x AS TYPE(some_expression)) FROM ...
> 
> Yeah, that would work.  Quick-hack proof-of-concept patch attached.

I'm amazed that this works without hacking the grammar itself, but in
retrospect that's expected.

> +     else if (pstate != NULL &&
> +                      list_length(typeName->typmods) == 1 &&
> +                      list_length(typeName->names) == 1 &&
> +                      strcmp(strVal(linitial(typeName->names)), "type") == 0)
> +     {
> +             /* TYPE(expression) notation */
> +             Node       *typexpr = (Node *) linitial(typeName->typmods);

This is a rather ugly, but I guess not untenable.  I suppose we don't
care about any actual typmod, do we?.  Will this be of any use with the
PostGIS types and such, for which the typmod is not merely a size limit?
Also INTERVAL has some funny typmod rules, not sure if that affects
usage of this construct.

-- 
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to