Re: DO INSTEAD and conditional rules - Mailing list pgsql-hackers

From David Wheeler
Subject Re: DO INSTEAD and conditional rules
Date
Msg-id 79e6a42116d6cd9a74bb021041d3953a@kineticode.com
Whole thread Raw
In response to Re: DO INSTEAD and conditional rules  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Apr 26, 2005, at 2:58 PM, Tom Lane wrote:

> ... which indeed can be a feature, not a bug, depending on what you're
> doing ...

Absolutely. An INSERT rule I have looks like this:

CREATE RULE insert_one AS
ON INSERT TO one WHERE NEW.id IS NULL
DO INSTEAD (  INSERT INTO _simple (id, guid, state, name, description)  VALUES (NEXTVAL('seq_kinetic'), NEW.guid,
NEW.state,NEW.name, 
 
NEW.description);
  INSERT INTO simple_one (id, bool)  VALUES (CURRVAL('seq_kinetic'), NEW.bool);
);

The call to NEXTVAL() in the first statement sets up a value I use in 
the second via CURRLVA().

Cheers,

David



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: DO INSTEAD and conditional rules
Next
From: Greg Stark
Date:
Subject: Re: [PERFORM] Bad n_distinct estimation; hacks suggested?