BUG #1175: insert rule action with defaults

From: "PostgreSQL Bugs List" <pgsql-bugs(at)postgresql(dot)org>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #1175: insert rule action with defaults
Date: 2004-06-21 23:30:51
Message-ID: 20040621233051.682FDCF4ADB@www.postgresql.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 1175
Logged by: Joe Carlson

Email address: joe(at)fruitfly(dot)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.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2004-06-22 02:14:53 Re: BUG #1175: insert rule action with defaults
Previous Message Michael Meskes 2004-06-21 09:12:55 Re: ECPG doesn't return the correct length for an empty