>>>>> "Greg" == "Greg Sabino Mullane" <greg@turnstep.com> writes:
>> They're mostly a foot-gun.
Greg> Lots of things in Postgres could be considered potential footGreg> guns. Frankly, I don't think rules are even
nearthe top ofGreg> such a list. Can you give examples of rule foot guns?
There are so many it's hard to know where to start.
Here are a couple of the more common ones:
1) any reference in an insert rule to NEW.col where col has a volatile default, or the expression in the insert
statementwas volatile, or the expression's value is changed by the insert, will do the wrong thing:
create table t (a integer);
create table t_log (a integer);
create rule t_ins AS ON insert TO t do also insert into t_log values (NEW.a);
insert into t values (floor(random()*1000)::integer);
select * from t;a
----33
(1 row)
select * from t_log; a
-----392
(1 row)
(think "nextval" or "uuid_generate_*" for more realistic examples)
2) any rule with multiple actions, each action is affected by the results of the previous ones. A classic example of
thisis in the use of OLD in delete or update rules; OLD _does not return a row_ if a previous action in the rule
deletedthe row or updated it so that it no longer matches.
--
Andrew (irc:RhodiumToad)