dbTalk Databases Forums  

[BUGS] BUG #2857: Sequence and table partitioning

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


Discuss [BUGS] BUG #2857: Sequence and table partitioning in the mailing.database.pgsql-bugs forum.



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

Default [BUGS] BUG #2857: Sequence and table partitioning - 12-25-2006 , 10:38 AM







The following bug has been logged online:

Bug reference: 2857
Logged by: Tomislav Karastojkovic
Email address: karastojko (AT) gmail (DOT) com
PostgreSQL version: 8.1.4, 8.2.0
Operating system: Linux
Description: Sequence and table partitioning
Details:

Sequence does not increase by 1 when tables is partitioned!
For example, let define 'parent' and 'child' tables, with column 'id' of
type 'serial':

CREATE TABLE parent(id serial, message text);
CREATE TABLE child() INHERITS(parent);
ALTER TABLE child ALTER id DROP DEFAULT;

Default value is dropped from the child table, so sequence is used only in
the 'parent' table.
If we set a rule

CREATE OR REPLACE RULE r AS ON INSERT TO parent DO INSTEAD INSERT INTO child
VALUES(NEW.id, NEW.message);

then each inserting into table 'parent' increases sequence 'parent_id_seq'
by 1, as it should. But if we add a condition for 'id' when setting the rule
like

CREATE OR REPLACE RULE r AS ON INSERT TO parent WHERE id>=1 AND id <= 100 DO
INSTEAD INSERT INTO child VALUES(NEW.id, NEW.message);

then the sequence is increasing by 5 when inserting into 'parent' table.
This seems to be a bug.

---------------------------(end of broadcast)---------------------------
TIP 6: explain analyze is your friend

Reply With Quote
  #2  
Old   
Tom Lane
 
Posts: n/a

Default Re: [BUGS] BUG #2857: Sequence and table partitioning - 12-25-2006 , 02:51 PM






"Tomislav Karastojkovic" <karastojko (AT) gmail (DOT) com> writes:
Quote:
CREATE OR REPLACE RULE r AS ON INSERT TO parent WHERE id>=1 AND id <= 100 DO
INSTEAD INSERT INTO child VALUES(NEW.id, NEW.message);

then the sequence is increasing by 5 when inserting into 'parent' table.
"id" is basically a macro that gets replaced with the expression being
inserted, ie, the nextval() call. So you're getting bit with multiple
evaluation.

There isn't any very safe way to do this sort of thing with a rule.
Consider using a trigger instead.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 4: Have you searched our list archives?

http://archives.postgresql.org


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.