BUG #1175: insert rule action with defaults - Mailing list pgsql-bugs

From PostgreSQL Bugs List
Subject BUG #1175: insert rule action with defaults
Date
Msg-id 20040621233051.682FDCF4ADB@www.postgresql.com
Whole thread Raw
Responses Re: BUG #1175: insert rule action with defaults
List pgsql-bugs
The following bug has been logged online:

Bug reference:      1175
Logged by:          Joe Carlson

Email address:      joe@fruitfly.org

PostgreSQL version: 7.3.2

Operating system:   linux

Description:        insert rule action with defaults

Details:

I realize this was discussed 2 years ago; the issue is
how to deal with default columns in rule-based actions.

The issue I have is tracking inserts or updates to a
collection of tables using a rule which will insert a
transaction record for that operation.

This illustrates the behavior:
create table silly (id serial, item varchar(20));
create table action (item_id integer, whence datetime);

create rule silly_insert_r as on insert to silly do
insert into action (item_id,whence)
values (new.id,'now');

insert into silly (item) value ('first');

select * from silly;
 id | item
----+-------
  2 | first
(1 row)

select * from action;
 item_id |         whence
---------+------------------------
       1 | 2004-06-21 16:24:51-07
(1 row)

So, in the rule expansion, the default column for id
is getting evaluation in a call to nextval, but this
value is not being used in the insert to silly.
One (namely, I) would like to have the same id values
without the second call to nextval.

I realize there are different ways to implement this
behavior as a workaround; but these become quite
complex in my real application. It would be good to
have the rule expansion happen after default columns
were identified and set rather than being specified
in separate operations.

pgsql-bugs by date:

Previous
From: Michael Meskes
Date:
Subject: Re: ECPG doesn't return the correct length for an empty
Next
From: Tom Lane
Date:
Subject: Re: BUG #1175: insert rule action with defaults