select t.name from tbl t (where "name" is not a column name)

From: raf <raf(at)raf(dot)org>
To: pgsql-general(at)postgresql(dot)org
Subject: select t.name from tbl t (where "name" is not a column name)
Date: 2010-02-24 01:07:50
Message-ID: 20100224010750.GA18679@raf.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

hi,

i've just noticed the following behaviour and was wondering
if there's any documentation to explain what it's for.

create table tbl(id serial primary key, a text, b text, c text);
insert into tbl(a, b, c) values ('abc', 'def', 'ghi');
insert into tbl(a, b, c) values ('jkl', 'mno', 'pqr');
insert into tbl(a, b, c) values ('stu', 'vwx', 'yza');
select t.name from tbl t;
drop table tbl;

results in:

name
-----------------
(1,abc,def,ghi)
(2,jkl,mno,pqr)
(3,stu,vwx,yza)

you can select t.name from tbl t even though "name" isn't the name
of a column in the table and you get this tuple-like version of the
each row. it doesn't work without the "t" alias and of course it
doesn't work if name really is the name of a column in the table.

so, what's this behaviour for, and, is there an equivalent
way to do it when "name" is the name of a column? i doubt
that i need this behaviour for anything. i'm just curious
and didn't see any mention of this in the documentation for
the select statement.

cheers,
raf

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Net Tree Inc. 2010-02-24 01:56:35 Re: how do I do dump and restore without bugging with constraint?
Previous Message Ben Chobot 2010-02-23 22:11:01 Re: pg_buffercache's usage count