Skip site navigation (1) Skip section navigation (2)

Rule/sequence weirdness

From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Rule/sequence weirdness
Date: 2004-08-31 21:17:51
Message-ID: 200408311417.51161.scrawford@pinpointresearch.com (view raw or flat)
Thread:
Lists: pgsql-general
I have some processes that create data. Other processes run by cron 
periodically take that data and insert it into appropriate tables in 
a 7.4.1 database.

In some cases the delay from process end to insert seems excessive so 
I'm trying to track the problem with a rule that creates a log record 
every time a record is inserted into the main table.

Unfortunately the sequences are not being updated as I would wish.

Here's the scoop:

I want to monitor inserts to table "foo":
guid: integer not null default nextval('public.guid'::text)
end_time: integer 
...

The inserts will be logged into table "foo_latelog"
guid: integer
inserttime: timestamp without time zone default now()
end_time: timestamp without time zone

Rule foo_late_rule inserts the data:
  ON INSERT TO foo DO
      INSERT INTO foo_latelog (guid, end_time)
      VALUES (new.guid, (new.end_time)::abstime)

I expected the guid to match. Unfortunately there are no matching 
guids between the two tables. It appears that the sequence is being 
called twice so the guid in the log table is one greater than the 
guid in the main table.

Did I miss something in my rule logic or is this a bug?

Cheers,
Steve

Responses

pgsql-general by date

Next:From: Mike NolanDate: 2004-08-31 21:24:00
Subject: Re: Single Row Table?
Previous:From: Mike NolanDate: 2004-08-31 21:15:23
Subject: Re: Single Row Table?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group