Feature request: support queries with returning on simple views with automatic update

Поиск
Список
Период
Сортировка
Искать

Feature request: support queries with returning on simple views with automatic update

От:
Attila Soki <atiware@gmx.net>
Дата:
hi all,

the automatic update for views is really a helpful feature, but i think it would be more useful with returning support.

currently we have to construct a rule/trigger to support queries like
'insert into simple_view returning pk'

is it possible (or desired) to implement something like an automatic returning support?
it would be great if i could simply write 'insert into simple_view returning col1' or 'insert into simple_view returning col2' and postgres would make the magic behind.

(a slightly changed text from the pg rules documentation)
The RETURNING logic of the automatic update feature would be used only if the automatic update is triggered by an INSERT RETURNING, UPDATE RETURNING, or DELETE RETURNING command respectively. When the automatic update is triggered by a command without RETURNING, the RETURNING logic will be ignored.

thanks

regards,
Attila



Re: Feature request: support queries with returning on simple views with automatic update

От:
Michael Paquier <michael.paquier@gmail.com>
Дата:
> it would be great if i could simply write 'insert into simple_view returning col1' or 'insert into simple_view returning col2' and postgres would make the magic behind.
You can do it with 9.3~ servers already. Here is an example:
=# create table aa (a int);
CREATE TABLE
=# insert into aa values (1);
INSERT 0 1
=# create view aav as select * from aa;
CREATE VIEW
=# insert into aav values (2) returning a;
 a
---
 2
(1 row)
INSERT 0 1
=# delete from aav where a = 1 returning a;
 a
---
 1
(1 row)
DELETE 1

Regards,
-- 
Michael

FAQ