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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search for
  Advanced Search

BUG #3945: unexpected ON INSERT rule behaviour


  • From: "Holger Klawitter" <info(at)klawitter(dot)de>
  • To: pgsql-bugs(at)postgresql(dot)org
  • Subject: BUG #3945: unexpected ON INSERT rule behaviour
  • Date: Fri, 8 Feb 2008 22:20:18 GMT
  • Message-id: <200802082220(dot)m18MKIM1032932(at)wwwmaster(dot)postgresql(dot)org>

The following bug has been logged online:

Bug reference:      3945
Logged by:          Holger Klawitter
Email address:      info(at)klawitter(dot)de
PostgreSQL version: 8.2.6
Operating system:   Linux/i386
Description:        unexpected ON INSERT rule behaviour
Details: 

Well,
this is probably not really a bug, more a feature
deeply buried in the query-tree-concept worth placed as a pitfall warning in
the documentation :-)

The following code:
CREATE TABLE a (a int);
CREATE TABLE b (b int);

CREATE OR REPLACE RULE a_to_b
AS ON INSERT TO a
DO ALSO INSERT INTO b VALUES (NEW.a);

INSERT INTO a VALUES ( 1 );
INSERT INTO a VALUES ((SELECT max(a)+1 from a));

SELECT * from b;

Produces the following output:
 b 
---
 1
 3         <---- 2 expected here
(2 rows)

One would expect 1 and 2 to be stored in b.

The problem is that NEW.a is not the *value* being inserted. Instead, NEW
reproduces the unevaluated
selected statement.

Regards
  Holger



Home | Main Index | Thread Index

Privacy Policy | PostgreSQL Archives hosted by Command Prompt, Inc. | Designed by tinysofa
Copyright © 1996 – 2008 PostgreSQL Global Development Group