X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 8A62B3A465F for ; Wed, 27 Oct 2004 14:18:32 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 37977-09 for ; Wed, 27 Oct 2004 13:18:23 +0000 (GMT) Received: from host5-mail.mastak.com (host5-mail.mastak.com [217.106.234.105]) by svr1.postgresql.org (Postfix) with SMTP id 3C2463A3B9F for ; Wed, 27 Oct 2004 14:18:18 +0100 (BST) Received: (qmail 23424 invoked by uid 0); 27 Oct 2004 13:18:09 -0000 Received: from unknown (HELO ?10.254.1.111?) (81.26.151.146) by host5-mail.mastak.com with SMTP; 27 Oct 2004 13:18:09 -0000 Message-ID: <417FA067.5030506@inpris.ru> Date: Wed, 27 Oct 2004 17:19:35 +0400 From: "Dmitry P. Ovechkin" User-Agent: Mozilla Thunderbird 0.7.1 (X11/20040626) X-Accept-Language: en-us, en MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: RULE and default nextval() column Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200410/194 X-Sequence-Number: 19297 Hello. I'mtrying to implement history tables using rules. I have test_table ---------- create sequence history_seq start 1; create sequence test_sequence; # source table drop table test_table; create table test_table ( i integer default nextval('test_sequence'), c character(10) ); # history table create table test_table_history ( hist integer default nextval('history_seq'), i integer, c character(10) ); # rule to save history create rule test_table_history_insert as on insert to test_table do insert into test_table_history values ( nextval('history_seq'), new.i, new.c ); # Then I try to insert into test_table; test=> insert into test_table values( nextval('test_sequence'), 'a'); INSERT 3299176 1 test=> insert into test_table (c) values('a'); INSERT 3299178 1 drweb=> select * from test_table; i | c ---+------------ 1 | a 3 | a (2 rows) test=> select * from test_table_history; hist | i | c ------+---+------------ 1 | 2 | a 2 | 4 | a (2 rows) ========== Problem is : value of "i" field increments during insertion into both test_table and test_table history. This also happens if I omit "i" in insert statement and let it be filled by default. Can something be done to avoid it? Sincerely, Dmitry Ovechkin.