Hello all,
Have the problem with using RULEs (is it a RULE's bug?):
Do the following:
1) Create table 'num' with column of a type SERIAL, e.g.
CREATE TABLE num (id SERIAL, num INT4);
2) Create table 'num_log' (for logging insertions
in table 'num'), e.g.
CREATE TABLE num_log (num_id INT4, num_val INT4);
3) Create rule 'num_rule' (that makes logging), e.g.
CREATE RULE num_rule AS
ON INSERT TO num
DO INSERT INTO num_log VALUES (NEW.id, NEW.num);
4) Insert into 'num', e.g.
INSERT INTO num (num) VALUES (123);
5) SELECT * FROM num;
id|num
------
2|123
6) SELECT * FROM num_log;
num_id|num_val
--------------
1| 123
The problem is id != num_id, e.g. the 'id' logged with
RULE differs from real 'id' of the inserted (into table 'num')
row.
Did anybody encountered the same problem, if so how it were solved?
Is it a bug?
Thanks!
--
Vladimir Zolotych gsmith@eurocom.od.ua