rules problem

Поиск
Список
Период
Сортировка
От Vladimir V. Zolotych
Тема rules problem
Дата
Msg-id 3916E46F.2E4DC655@eurocom.od.ua
обсуждение исходный текст
Список 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@eurocom.od.ua
 

В списке pgsql-admin по дате отправления:

Предыдущее
От: "Andrei N.Sobchuck"
Дата:
Сообщение:
Следующее
От: Nicolas Huillard
Дата:
Сообщение: RE: rules problem