Unexpected result from selecting an aliased but non-existing column called "name"

Lists: pgsql-general
From: Ian Barwick <barwick(at)gmail(dot)com>
To: PG-General Mailing List <pgsql-general(at)postgresql(dot)org>
Subject: Unexpected result from selecting an aliased but non-existing column called "name"
Date: 2010-03-09 08:50:45
Message-ID: 1d581afe1003090050q8608a47rb222729becf19ffd@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi

I was wondering where some spurious information in a query was
coming from - it looked like something was inserting all the
values of a table row as a comma-separated list.

It turns out I was attempting to reference a non-existent column
called (literally) "name", which instead of throwing an error produces
the aforementioned list. This only seems to happen with "name", and
only if it is referenced with the table name or alias.

To reproduce:

test=> CREATE table xx(id int, val text);
CREATE TABLE
test=> INSERT INTO xx values(1,'hello world');
INSERT 0 1
test=> SELECT name FROM xx;
ERROR: column "name" does not exist
LINE 1: SELECT name FROM xx;

test=> SELECT xx.name from xx;
name
-------------------
(1,"hello world")
(1 row)

test=> SELECT xx.foobar FROM xx;
ERROR: column xx.foobar does not exist
LINE 1: SELECT xx.foobar FROM xx;

Reproducible on 8.4.1 and 8.4.2; does not work in 8.3.1
(old test version I happen to have hanging around).

Questions:
- is this a feature?
- and if so, where is it documented?
(given that the key word in this is "name", this is a tricky one
to research).

Thanks for any pointers.

Ian Barwick


From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Ian Barwick <barwick(at)gmail(dot)com>
Subject: Re: Unexpected result from selecting an aliased but non-existing column called "name"
Date: 2010-03-09 14:21:08
Message-ID: 201003090621.09130.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Tuesday 09 March 2010 12:50:45 am Ian Barwick wrote:
> Hi
>
> I was wondering where some spurious information in a query was
> coming from - it looked like something was inserting all the
> values of a table row as a comma-separated list.
>
> It turns out I was attempting to reference a non-existent column
> called (literally) "name", which instead of throwing an error produces
> the aforementioned list. This only seems to happen with "name", and
> only if it is referenced with the table name or alias.
>
>
>
>
> Ian Barwick

See this recent thread for explanation:
http://archives.postgresql.org/pgsql-general/2010-02/msg01038.php

--
Adrian Klaver
adrian(dot)klaver(at)gmail(dot)com


From: Ian Barwick <barwick(at)gmail(dot)com>
To: adrian(dot)klaver(at)gmail(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected result from selecting an aliased but non-existing column called "name"
Date: 2010-03-17 14:11:40
Message-ID: 1d581afe1003170711l42416d5di421a77fc3ed52576@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi Adrian,

2010/3/9 Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>:
> On Tuesday 09 March 2010 12:50:45 am Ian Barwick wrote:
>> Hi
>>
>> I was wondering where some spurious information in a query was
>> coming from - it looked like something was inserting all the
>> values of a table row as a comma-separated list.
>>
>> It turns out I was attempting to reference a non-existent column
>> called (literally) "name", which instead of throwing an error produces
>> the aforementioned list. This only seems to happen with "name", and
>> only if it is referenced with the table name or alias.
>>
>> Ian Barwick
>
> See this recent thread for explanation:
> http://archives.postgresql.org/pgsql-general/2010-02/msg01038.php

Thanks for the info, apologies for the delay in replying.

Certainly explains what's going on, though it seems a bit of a "gotcha".

Regards

Ian Barwick