pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Vladimir V. Zolotych <gsmith@eurocom.od.ua>
To: pgsql-admin@postgresql.org
Subject: rules problem
Date: Mon, 08 May 2000 18:59:44 +0300
Message-ID: <3916E46F.2E4DC655@eurocom.od.ua> (raw)

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

view thread (2+ messages)  latest in thread

Message-ID: <3916E46F.2E4DC655@eurocom.od.ua>
Permalink:  ../3916E46F.2E4DC655@eurocom.od.ua/
Also on:    postgresql.org/message-id/3916E46F.2E4DC655@eurocom.od.ua

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: gsmith@eurocom.od.ua
  Subject: Re: rules problem
  In-Reply-To: <3916E46F.2E4DC655@eurocom.od.ua>
  References: <3916E46F.2E4DC655@eurocom.od.ua>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox