Rule action ordering

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jan Wieck <wieck(at)hub(dot)org>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Rule action ordering
Date: 2001-07-06 18:29:03
Message-ID: 17658.994444143@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers pgsql-hackers

Jan Wieck <wieck(at)hub(dot)org> writes:
> Fire rule actions ON INSERT after original statement (if not INSTEAD).

It seems to me that this change of ordering should apply to
qual_products (ie, original statement with negation of a conditional
INSTEAD rule's condition) as well as to the unvarnished original
statement in the non-INSTEAD case. Otherwise it's just about impossible
to give a coherent statement of what the behavior is.

However, when I tried making that change, a whole bunch of differences
popped up in the rules regression test. They seemed to come from this
example:

create rule rtest_nothn_r1 as on insert to rtest_nothn1
where new.a >= 10 and new.a < 20 do instead (select 1);

In the old regime, the SELECT got done before the INSERT, so psql throws
away the SELECT result and you see no output. In the new regime, the
SELECT gets done last and you see its output. What might be even more
confusing to newbies, you see SELECT output of zero rows when the rule's
WHERE condition fails (since the select is done anyway, but with a false
condition).

My feeling is that I should make the change and adjust the rule test's
expected output (probably by changing this rule to DO INSTEAD NOTHING).
Comments?

regards, tom lane

In response to

Browse pgsql-committers by date

  From Date Subject
Next Message Bruce Momjian 2001-07-06 18:52:22 Re: pgsql/src/interfaces/libpq fe-connect.c fe-exe ...
Previous Message Bruce Momjian 2001-07-06 18:23:16 Re: pgsql/src/backend/rewrite rewriteHandler.c

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2001-07-06 18:33:36 Re: FE/BE protocol oddity
Previous Message Bruce Momjian 2001-07-06 18:23:16 Re: pgsql/src/backend/rewrite rewriteHandler.c