![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
I know... That was a typo in my sql :-) But for this example it doesn't matter - that view/table is only needed to illustrate the rules behaviour on insert. |
#2
| |||
| |||
|
|
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. Yeah... that's what I was afraid of :-( |
#3
| |||
| |||
|
|
Dmitry Tkach <dmitry (AT) openratings (DOT) com> writes: The problem is that in the 'real life' situation the condition is a lot more complicated than this simple is null test... I hate having to duplicate it, and I hate even more having to evaluate it twice on every insert :-( Why evaluate it twice? The DO INSTEAD NOTHING rule should be unconditional. Right. But the problem is I don't want to discard the invalid entries |
#4
| |||
| |||
|
|
Ok... What's wrong with this one then testdb=# insert into test values (null, null); ERROR: ExecInsert: Fail to add null value in not null attribute x |
#5
| |||
| |||
|
|
But what the hell is my problem then??? I swear, I do insert into the view there :-) It's a really huge view, looking at a whole bunch of different tables... I'd hate having to post the whole thing... |
#6
| |||
| |||
|
|
Dmitry Tkach <dmitry (AT) openratings (DOT) com> writes: But what the hell is my problem then??? I swear, I do insert into the view there :-) It's a really huge view, looking at a whole bunch of different tables... I'd hate having to post the whole thing... All I can guess is a bug (or pilot error) that's triggered by the more complex view. I think you'll just have to try to whittle down the failure to something you can post. regards, tom lane |
#7
| |||
| |||
|
|
create rule insert_test as on insert to test_view where new.x is not null and new.y is not null do instead ( insert into test select new.* union select new.*; ); |
#8
| ||||
| ||||
|
|
Dmitry Tkach <dmitry (AT) openratings (DOT) com> writes: create rule insert_test as on insert to test_view where new.x is not null and new.y is not null do instead ( insert into test select new.* union select new.*; ); Mmm. In CVS tip that throws ERROR: UNION/INTERSECT/EXCEPT member statement may not refer to other relations of same query level Actually, I just used that new.* as an example (if I understand this |
|
which was a check added as a result of this discussion thread: http://archives.postgresql.org/pgsql...2/msg00693.php I'll take a look at that thread, thanks! |
|
I am sure you are running into some misbehavior associated with the fact that the rule transformation generates a bogusly-structured SQL query, and 7.2 isn't noticing. Not just 7.2... I was testing this in 7.3 - it has the same problem |
|
I'd like to support this case someday, but it's not clear how... I don't know if it helps, but somehow if I do |
#9
| |||
| |||
|
|
Something like insert into test select null,null union select 1,2 where false has the same problem... and it doesn't refer to any relations. |
|
Not just 7.2... I was testing this in 7.3 - it has the same problem |
|
insert into test select * from (select null,null union select 1,2 where false) as dummy ... that works fine. |
#10
| |||
| |||
|
|
Sure, but it is inside the rule that has 'where x is not null and y is not null' on it as a qualifier, so with my test example it should just never get executed in the first place. |
![]() |
| Thread Tools | |
| Display Modes | |
| |