Cannot query views with WHERE clause on renamed columns

Started by Alexander Reichstadtalmost 12 years ago3 messagesgeneral
Jump to latest

Hi,

I try to do what seems to be totally simple, but it fails. If I query a view that contains renamed columns without any qualifier like

SELECT * FROM myview

it displays everything. If however I do

SELECT reanmedviewcolumn FROM myview

It tells me column does not exist which in fact does. I can query any non-renamed columns. But the renamed ones I can neither call by their original name, not int he SELECT part nor in the WHERE clause.

I can neither leave the view with just the original names as it's a selfjoin.

What do I need to do?

Thanks
Alex

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

#2David G. Johnston
david.g.johnston@gmail.com
In reply to: Alexander Reichstadt (#1)
Re: Cannot query views with WHERE clause on renamed columns

Alexander Reichstadt wrote

Hi,

I try to do what seems to be totally simple, but it fails. If I query a
view that contains renamed columns without any qualifier like

SELECT * FROM myview

it displays everything. If however I do

SELECT reanmedviewcolumn FROM myview

It tells me column does not exist which in fact does. I can query any
non-renamed columns. But the renamed ones I can neither call by their
original name, not int he SELECT part nor in the WHERE clause.

I can neither leave the view with just the original names as it's a
selfjoin.

What do I need to do?

Show us your actual code that is failing?

The general idea of what you are saying indeed works:

BEGIN;

CREATE VIEW myview AS SELECT 'one'::text AS one, 'two'::text AS two;

SELECT one FROM myview WHERE two = 'three';

ROLLBACK;

David J.

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Cannot-query-views-with-WHERE-clause-on-renamed-columns-tp5809873p5809880.html
Sent from the PostgreSQL - general mailing list archive at Nabble.com.

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

#3Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alexander Reichstadt (#1)
Re: Cannot query views with WHERE clause on renamed columns

Alexander Reichstadt <lxr@mac.com> writes:

I try to do what seems to be totally simple, but it fails. If I query a view that contains renamed columns without any qualifier like

SELECT * FROM myview

it displays everything. If however I do

SELECT reanmedviewcolumn FROM myview

It tells me column does not exist which in fact does.

What do you mean by a "renamed column"? A concrete example would help
here.

regards, tom lane

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