Search Postgresql Archives

Re: insert into a view?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Karen Hill" <karen_hill22@xxxxxxxxx> writes:
> Tried it but didn't work.  It gave me a hint though to try triggers.
> Can anyone show me how to do an insert into a view using triggers?

I hope it said rules, because you can't put a trigger on a view.

regression=# create table t(f1 int, f2 text);
CREATE TABLE
regression=# create view v as select * from t;
CREATE VIEW
regression=# insert into v values(22, 'foo');
ERROR:  cannot insert into a view
HINT:  You need an unconditional ON INSERT DO INSTEAD rule.
regression=# create rule r as on insert to v do instead
regression-# insert into t values(new.*);
CREATE RULE
regression=# insert into v values(22, 'foo');
INSERT 0 1
regression=# select * from t;
 f1 | f2  
----+-----
 22 | foo
(1 row)


			regards, tom lane


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux