postgres question: Views with duplicate field names
От | Ryan Murphy |
---|---|
Тема | postgres question: Views with duplicate field names |
Дата | |
Msg-id | CAHeEsBcraekb-+KKOftn1svvwrSsa4_hYOaYSqz2+6jo+GiyPw@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: postgres question: Views with duplicate field names
|
Список | pgsql-general |
Hello, I have a question about views in Postgres.
Given a table like so:
create table todo (
id serial,
task text,
done_time timestamp default null
);
id serial,
task text,
done_time timestamp default null
);
it is legal (though perhaps not advised, by some) to query it like so:
select task, * from todo;
This gives a result with 2 redundant "task" fields (with duplicate names):
task | id | task | done_time
--------------+----+---------- ----+-----------
wash the dog | 1 | wash the dog |
--------------+----+----------
wash the dog | 1 | wash the dog |
However, if I try to make a view of this I hit a problem: views can't have duplicate field names:
create view task2 as select task, * from todo;
ERROR: column "task" specified more than once
I understand this may seem like a silly thing to want to do, but my question is if there is an easy way to automatically de-dup the columns of the query so I can create a view from it. Or is there any fundamental reason why views can't be allowed to have duplicate columns, just like the result set above?
Thanks!

Ryan
В списке pgsql-general по дате отправления: