Tom Lane wrote:
>Dmitry Tkach <dmitry@openratings.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
completely...
So, it would have to be *three* rules, not just two - like:
create rule skip_null as on insert to test_view where x is null do instead
insert into invalid_entries ('NULL DATA', new.*);
create rule insert_test as on insert to test_view where is is not null
do instead
insert into test values (new.*);
create rule dummy_insert as on insert to test_view do instead nothing;
... so x is null ends up being evaluated twice...
Dima