Re: Name column - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Name column
Date
Msg-id 4C9C7EF7.2010107@enterprisedb.com
Whole thread Raw
In response to Name column  (Vlad Arkhipov <arhipov@dc.baikal.ru>)
Responses Re: Name column  (Robert Haas <robertmhaas@gmail.com>)
List pgsql-hackers
On 24/09/10 13:02, Vlad Arkhipov wrote:
> I have just come across a weird thing. It works for any table and seems
> to be not documented.
>
> SELECT c.name FROM (VALUES(1, 'A', true)) c;
> SELECT c.name FROM pg_class c;
>
> And it does not work in these cases:
>
> SELECT name FROM (VALUES(1, 'A', true));
> SELECT name FROM pg_class;

For historical reasons PostgreSQL supports calling a function with a 
single argument like "column.function", in addition to 
"function(column)". There is a function "name(text)" that casts the 
input to the 'name' datatype, so your example casts the row to text and 
from text to name.

It is mentioned in the documentation at
http://www.postgresql.org/docs/8.4/interactive/xfunc-sql.html
Section "34.4.2. SQL Functions on Composite Types".

--   Heikki Linnakangas  EnterpriseDB   http://www.enterprisedb.com


pgsql-hackers by date:

Previous
From: Vlad Arkhipov
Date:
Subject: Name column
Next
From: Simon Riggs
Date:
Subject: Re: Configuring synchronous replication