dbTalk Databases Forums  

[BUGS] BUG #2563: In rules: recalculation of input expression on each access

mailing.database.pgsql-bugs mailing.database.pgsql-bugs


Discuss [BUGS] BUG #2563: In rules: recalculation of input expression on each access in the mailing.database.pgsql-bugs forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
AT
 
Posts: n/a

Default [BUGS] BUG #2563: In rules: recalculation of input expression on each access - 08-04-2006 , 09:13 AM







The following bug has been logged online:

Bug reference: 2563
Logged by: ivankob
Email address: ivankob (AT) front (DOT) ru
PostgreSQL version: 8.1.4
Operating system: Linux
Description: In rules: recalculation of input expression on each
access
Details:

For a testcase like :

CREATE SEQUENCE seq1;

CREATE TABLE t1 (
id INTEGER DEFAULT NEXTVAL('"seq1"'::text),
code INTEGER,
data TEXT
);

CREATE TABLE s1 (
id INTEGER,
code INTEGER,
state BOOLEAN
);

INSERT INTO t1 (code,data) VALUES (100,'Green elaphant');
INSERT INTO s1 VALUES (currval('"seq1"'::text),100,'t');

INSERT INTO t1 (code,data) VALUES (101,'Mad tortoise');
INSERT INTO s1 VALUES (currval('"seq1"'::text),101,'f');

-----------
CREATE VIEW v1 AS
SELECT a.code, a.data FROM t1 a, s1 b WHERE a.id=b.id AND a.code=b.code AND
b.state = 't';
------------
CREATE RULE rule1 ON INSERT TO v1 DO INSTEAD (
INSERT INTO t1 ( id, code, data) VALUES ( nextval('"seq1"'::text),
NEW.code, NEW.data );
INSERT INTO s1 ( id, code, state ) VALUES ( currval('"seq1"'::text),
NEW.code, 't' );
);
------------

INSERT INTO v1 (code,data) VALUES (
(SELECT MAX(code) FROM t1)+1,
'Penguin-sprinter'
);

after run, it seems that "(SELECT MAX(code) FROM t1)+1" is performed twice
(
on each NEW.code ) in the rule since "s1.code" results in greater than
"t1.code" by "1" what's wrong.
Access by reference not value ?

---------------------------(end of broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo (AT) postgresql (DOT) org so that your
message can get through to the mailing list cleanly

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.