Thread: BUG #2017: column labels ignored on selects from views

BUG #2017: column labels ignored on selects from views

From
"Jolly Chen"
Date:
The following bug has been logged online:

Bug reference:      2017
Logged by:          Jolly Chen
Email address:      jolly@gauntletsystems.com
PostgreSQL version: 8.1RC1
Operating system:   Mac OS X 10.4.3
Description:        column labels ignored on selects from views
Details:

Note how the column labels work for v2 but not for v1. This problem causes
columns to be mistakenly missing in JDBC ResultSets.


testdb=# create table foo (f1 integer);
CREATE TABLE
testdb=# insert into foo values (1);
INSERT 0 1
testdb=# insert into foo values (2);
INSERT 0 1
testdb=# create view v1 as select sum(f1) as sum from foo;
CREATE VIEW
testdb=# select * from v1;
 sum
-----
   3
(1 row)

testdb=# select sum as s from v1;
 sum
-----
   3
(1 row)

testdb=# create view v2 as select f1*10 as tenX from foo;
CREATE VIEW
testdb=# select * from v2;
 tenx
------
   10
   20
(2 rows)

testdb=# select tenX as t from v2;
 t
----
 10
 20
(2 rows)

testdb=# select version();
                                                                    version

----------------------------------------------------------------------------
-------------------------------------------------------------------
 PostgreSQL 8.1RC1 on powerpc-apple-darwin8.3.0, compiled by GCC
powerpc-apple-darwin8-gcc-4.0.0 (GCC) 4.0.0 (Apple Computer, Inc. build
5026)(1 row)

testdb=#

Re: BUG #2017: column labels ignored on selects from views

From
Tom Lane
Date:
"Jolly Chen" <jolly@gauntletsystems.com> writes:
> testdb=# select sum as s from v1;
>  sum
> -----
>    3
> (1 row)

Good catch.  8.0 and earlier get this right, so it's a regression we
induced somewhere in 8.1 development ... wonder where?

            regards, tom lane

Re: BUG #2017: column labels ignored on selects from views

From
Tom Lane
Date:
"Jolly Chen" <jolly@gauntletsystems.com> writes:
> Description:        column labels ignored on selects from views

Fixed --- turns out the problem was in some recently-added code to
eliminate unnecessary SubqueryScan nodes.  The resnames attached
to the SubqueryScan targetlist items have to be moved down to its
child node, not just dropped.

Thanks for the report!

            regards, tom lane