| From: | "Vladimir V(dot) Zolotych" <gsmith(at)eurocom(dot)od(dot)ua> | 
|---|---|
| To: | pgsql-admin(at)postgresql(dot)org | 
| Subject: | rules problem | 
| Date: | 2000-05-08 15:59:44 | 
| Message-ID: | 3916E46F.2E4DC655@eurocom.od.ua | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-admin | 
Hello all,
Encountered the problem with using RULEs. Cannot log
(e.g. write some info about insertions into sepearate table)
insertions properly. Detailed description (not long or sophisticated)
follows:
I do:
1) CREATE TABLE colors (id SERIAL, color TEXT);
2) Create table for log info:
CREATE TABLE colors_log (color_id INT4, color TEXT);
3) Create RULE that actually makes log:
   CREATE RULE log_color
   AS ON INSERT
   TO colors
   DO INSERT INTO colors_log VALUES (NEW.id, NEW.color);
4) Make some insertions:
INSERT INTO colors (color) VALUES ('red');
The same for 'green', 'blue'.
5) SELECT * FROM colors;
   id|color
   --+-----
    2|red
    4|green
    6|blue
   Here appears the first question:
   why 'id' is 2, 4, 6, not 1,  2, 3?
7) SELECT * FROM colors_log;
   color_id|color
   --------+-----
          1|red
          3|green
          5|blue
   The problem is: the 'id's differ. E.g.,
   In colors_log table the saved 'id' are wrong.
Thanks!
--
Vladimir Zolotych                         gsmith(at)eurocom(dot)od(dot)ua
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nicolas Huillard | 2000-05-08 20:39:20 | RE: rules problem | 
| Previous Message | Andrei N.Sobchuck | 2000-05-08 09:26:52 |