Re: [BUGS] INSTEAD rule bug? - Mailing list pgsql-general

From Dmitry Tkach
Subject Re: [BUGS] INSTEAD rule bug?
Date
Msg-id 3F143F73.1060105@openratings.com
Whole thread Raw
In response to Re: [BUGS] INSTEAD rule bug?  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
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



pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: [BUGS] INSTEAD rule bug?
Next
From: Frank Finner
Date:
Subject: Re: Are you frustrated with PostgreSQL