From: | Dmitry Tkach <dmitry(at)openratings(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-bugs(at)postgresql(dot)org, pgsql-general(at)postgresql(dot)org |
Subject: | Re: [GENERAL] INSTEAD rule bug? |
Date: | 2003-07-15 19:12:05 |
Message-ID: | 3F145205.9060403@openratings.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs pgsql-general |
>
>
>Oh, I see what you're on about. Sorry, a "DO INSTEAD NOTHING" only
>suppresses the original command, it does not suppress other rules.
>I think what you want is to make the insert_test rule conditional
>on x being not null.
>
> regards, tom lane
>
>
Ok... What's wrong with this one then (three rules are conditional - if
x is null or y is null, the entry is rejected, if x is not null and y is
not null, it is inserted, the fourth rull is a dummy to prevent the
planner from complaining about not being able to insert into a view):
testdb=# create table test (x int not null, y int not null);
CREATE TABLE
testdb=# create view test_view as select * from test;
CREATE VIEW
testdb=# create rule reject_x as on insert to test_view where new.x is
null do instead
testdb=# create table test_reject (x int, y int, reason text);
CREATE TABLE
testdb=# create rule reject_x as on insert to test_view where x is null
do instead insert into test_reject values (new.*, 'NULL x');
CREATE RULE
testdb=# create rule reject_y as on insert to test_view where y is null
do instead insert into test_reject values (new.*, 'NULL y');
CREATE RULE
testdb=# create rule insert_test as on insert to test_view where x is
not null and y is not null do instead insert into test values (new.*);
CREATE RULE
testdb=# create rule insert_dummy as on insert to test_view do instead
nothing;
CREATE RULE
testdb=# insert into test values (null, null);
ERROR: ExecInsert: Fail to add null value in not null attribute x
Now, why does this fail?
The only rule that attempts to insert anything into test has 'x is not
null and y is not null' as the qualifier.
What's wrong?
Thanks!
Dima
From | Date | Subject | |
---|---|---|---|
Next Message | Raymond Chui | 2003-07-15 19:15:58 | Timestamp problem |
Previous Message | Dmitry Tkach | 2003-07-15 17:52:51 | Re: [GENERAL] INSTEAD rule bug? |
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-07-15 19:44:07 | Re: [GENERAL] INSTEAD rule bug? |
Previous Message | Darko Prenosil | 2003-07-15 18:48:29 | Re: Couple Postgres View Questions |