strange behavior, hoping for an explanation

Started by Chris Traversover 14 years ago4 messagesgeneral
Jump to latest
#1Chris Travers
chris.travers@gmail.com

Hi;

I have found recently that tables in certain contexts seem to have a
name pseudocolumn. I was wondering if there is any documentation as
to what this is and what it signifies.

postgres=# CREATE table TEST2 (a text, b text);
CREATE TABLE
postgres=# INSERT INTO test2 values ('aaaa', 'bbbb');
INSERT 0 1
postgres=# select t.name FROM test2 t;
name
-------------
(aaaa,bbbb)
(1 row)

However:

postgres=# select name FROM test2 t;
ERROR: column "name" does not exist
LINE 1: select name FROM test2 t;

This isn't making any sense to me. Are there certain circumstances
where a tuple is cast to something like varchar(63)? Does this pose
pitfals for any columns named 'name' in other contexts?

Best Wishes,
Chris Travers

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Chris Travers (#1)
Re: strange behavior, hoping for an explanation

Chris Travers <chris.travers@gmail.com> writes:

I have found recently that tables in certain contexts seem to have a
name pseudocolumn. I was wondering if there is any documentation as
to what this is and what it signifies.

I/O conversion cast from composite type to string. You might find
this 9.1 patch informative:
http://git.postgresql.org/gitweb/?p=postgresql.git&amp;a=commitdiff&amp;h=543d22fc7423747afd59fe7214f2ddf6259efc62
There's also relevant discussion in the mailing lists shortly before
that.

regards, tom lane

#3pasman pasmański
pasman.p@gmail.com
In reply to: Chris Travers (#1)
Re: strange behavior, hoping for an explanation

See documentation, chapter Viii.E.2.2.2

2011/11/11, Chris Travers <chris.travers@gmail.com>:

Hi;

I have found recently that tables in certain contexts seem to have a
name pseudocolumn. I was wondering if there is any documentation as
to what this is and what it signifies.

postgres=# CREATE table TEST2 (a text, b text);
CREATE TABLE
postgres=# INSERT INTO test2 values ('aaaa', 'bbbb');
INSERT 0 1
postgres=# select t.name FROM test2 t;
name
-------------
(aaaa,bbbb)
(1 row)

However:

postgres=# select name FROM test2 t;
ERROR: column "name" does not exist
LINE 1: select name FROM test2 t;

This isn't making any sense to me. Are there certain circumstances
where a tuple is cast to something like varchar(63)? Does this pose
pitfals for any columns named 'name' in other contexts?

Best Wishes,
Chris Travers

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

--
------------
pasman

#4Laurenz Albe
laurenz.albe@cybertec.at
In reply to: Chris Travers (#1)
Re: strange behavior, hoping for an explanation

Chris Travers wrote:

I have found recently that tables in certain contexts seem to have a
name pseudocolumn. I was wondering if there is any documentation as
to what this is and what it signifies.

postgres=# CREATE table TEST2 (a text, b text);
CREATE TABLE
postgres=# INSERT INTO test2 values ('aaaa', 'bbbb');
INSERT 0 1
postgres=# select t.name FROM test2 t;
name
-------------
(aaaa,bbbb)
(1 row)

However:

postgres=# select name FROM test2 t;
ERROR: column "name" does not exist
LINE 1: select name FROM test2 t;

This isn't making any sense to me. Are there certain circumstances
where a tuple is cast to something like varchar(63)? Does this pose
pitfals for any columns named 'name' in other contexts?

I tried to your sample in 9.1.1 and 9.2devel, and both gave me
ERROR: column t.name does not exist
as expected.

Yours,
Laurenz Albe