Re: Possible Bug

Lists: pgsql-general
From: Kaloyan Iliev Iliev <kaloyan(at)digsys(dot)bg>
To: pgsql-general(at)postgresql(dot)org
Subject: Possible Bug
Date: 2011-02-09 09:51:38
Message-ID: 4D5263AA.9050807@digsys.bg
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Hi,
I think I found something strange in PostgreSQL behavior. Here is an
example:

testdb=# CREATE TABLE test1 (test2 text, test3 text);
CREATE TABLE
testdb=# SELECT A.name FROM test1 A;
name
------
(0 rows)

testdb=# INSERT INTO test1 (test2,test3) VALUES ('1','2');
INSERT 0 1
testdb=# INSERT INTO test1 (test2,test3) VALUES ('3','4');
INSERT 0 1
testdb=# SELECT A.name FROM test1 A;
name
-------
(1,2)
(3,4)
(2 rows)

customer.20080408=# SELECT name FROM test1;
ERROR: column "name" does not exist
LINE 1: SELECT name FROM test1;

testdb=# SELECT version();

version
----------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.5 on amd64-portbld-freebsd8.1, compiled by GCC cc (GCC)
4.2.1 20070719 [FreeBSD], 64-bit
(1 row)

Obviously there is no column with name "name", but the SELECT query
(ONLY WHEN I USE ALIASES) returns result for it.
And if I have a column with name "name_en" and by mistake write it
"name", instead of error I receive strange data (ARRAY from all
columns), that I don't expect.

Could you tell me if this is a bug or some feature I haven't heard of.

Best regards,
Kaloyan Iliev


From: Robert Gravsjö <robert(at)blogg(dot)se>
To: kaloyan(at)digsys(dot)bg
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Possible Bug
Date: 2011-02-09 14:08:40
Message-ID: 4D529FE8.2070800@blogg.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 2011-02-09 10.51, Kaloyan Iliev Iliev wrote:
> Hi,
> I think I found something strange in PostgreSQL behavior. Here is an
> example:
>
>
> testdb=# CREATE TABLE test1 (test2 text, test3 text);
> CREATE TABLE
> testdb=# SELECT A.name FROM test1 A;
> name
> ------
> (0 rows)
>
> testdb=# INSERT INTO test1 (test2,test3) VALUES ('1','2');
> INSERT 0 1
> testdb=# INSERT INTO test1 (test2,test3) VALUES ('3','4');
> INSERT 0 1
> testdb=# SELECT A.name FROM test1 A;
> name -------
> (1,2)
> (3,4)
> (2 rows)
>
> customer.20080408=# SELECT name FROM test1;
> ERROR: column "name" does not exist
> LINE 1: SELECT name FROM test1;
>
>
> testdb=# SELECT version();
> version
> ----------------------------------------------------------------------------------------------------------
>
> PostgreSQL 8.4.5 on amd64-portbld-freebsd8.1, compiled by GCC cc (GCC)
> 4.2.1 20070719 [FreeBSD], 64-bit
> (1 row)
>
> Obviously there is no column with name "name", but the SELECT query
> (ONLY WHEN I USE ALIASES) returns result for it.
> And if I have a column with name "name_en" and by mistake write it
> "name", instead of error I receive strange data (ARRAY from all
> columns), that I don't expect.
>
> Could you tell me if this is a bug or some feature I haven't heard of.

Look up functional notation in
http://www.postgresql.org/docs/9.0/static/xfunc-sql.html#AEN46042

These are the same thing:
select name(test1) from test1;
select test.name from test1;

>
> Best regards,
> Kaloyan Iliev
>
>
>

--
Regards,
Robert "roppert" Gravsjö


From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org, kaloyan(at)digsys(dot)bg
Subject: Re: Possible Bug
Date: 2011-02-09 14:44:25
Message-ID: 201102090644.26376.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Wednesday, February 09, 2011 1:51:38 am Kaloyan Iliev Iliev wrote:
> Hi,
> I think I found something strange in PostgreSQL behavior. Here is an
> example:
>
>
> testdb=# CREATE TABLE test1 (test2 text, test3 text);
> CREATE TABLE
> testdb=# SELECT A.name FROM test1 A;
> name
> ------
> (0 rows)
>
> testdb=# INSERT INTO test1 (test2,test3) VALUES ('1','2');
> INSERT 0 1
> testdb=# INSERT INTO test1 (test2,test3) VALUES ('3','4');
> INSERT 0 1
> testdb=# SELECT A.name FROM test1 A;
> name
> -------
> (1,2)
> (3,4)
> (2 rows)
>
> customer.20080408=# SELECT name FROM test1;
> ERROR: column "name" does not exist
> LINE 1: SELECT name FROM test1;
>
>
> testdb=# SELECT version();
>
> version
> ---------------------------------------------------------------------------
> ------------------------------- PostgreSQL 8.4.5 on
> amd64-portbld-freebsd8.1, compiled by GCC cc (GCC) 4.2.1 20070719
> [FreeBSD], 64-bit
> (1 row)
>
> Obviously there is no column with name "name", but the SELECT query
> (ONLY WHEN I USE ALIASES) returns result for it.
> And if I have a column with name "name_en" and by mistake write it
> "name", instead of error I receive strange data (ARRAY from all
> columns), that I don't expect.
>
> Could you tell me if this is a bug or some feature I haven't heard of.

Depending on your point of view both. For a good explanation see:

http://www.depesz.com/index.php/2010/11/08/waiting-for-9-1-removed-autocast-
footgun/

As detailed above this feature will go away in 9.1.

>
> Best regards,
> Kaloyan Iliev

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