Re: insert into a view?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Karen Hill" <karen_hill22(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: insert into a view?
Date: 2006-05-02 00:32:48
Message-ID: 21400.1146529968@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Karen Hill" <karen_hill22(at)yahoo(dot)com> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris Velevitch 2006-05-02 06:53:58 How to join to delete
Previous Message Michael Fuhr 2006-05-02 00:31:47 Re: insert into a view?