Search Postgresql Archives

Re: RULES and QUALIFICATION for INSERT

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

 



srdjan wrote:
> I'll try to explain my problem with an example. 
> 
> -- I've got 2 tables and one view 
> CREATE TABLE a (name varchar(20) primary key, num integer); 
> CREATE TABLE b (town varchar(15), name varchar(20) references a(name)); 
> 
> CREATE VIEW vvv AS SELECT * FROM a NATURAL JOIN b; 
> 
> -- I've crated a rule in this way 
> 
> CREATE RULE rrr AS ON INSERT TO vvv 
> WHERE NEW.name = 'tom' 
> DO INSTEAD 
> INSERT INTO a VALUES (NEW.name, NEW.num); 
> 
> Trying a simple INSERT INTO vvv, I receive this message: 
> ERROR: cannot insert into a view 
> HINT: You need an unconditional ON INSERT DO INSTEAD rule. 
> 
> If I've understood well, the qualification (WHERE NEW.name = 'tom') is the condition under which the rule has to be executed. 
> Only if the condition is met, the rule is executed. 
> I noticed that if I remove the qualification, the rule works, but doing so
> I am not able anymore to test the condition. (I could overcame this problem
> with a trigger, but I'd prefer if someone could explain me how to do this with rules). 

What is the desired response to

INSERT INTO vvv (name, town, num) VALUES ('Karl', 'Leipzig', 18);

Should this generate an error message, do nothing, or insert something?

Yours,
Laurenz Albe

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


[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