From luca.rasconi@students.cefriel.it Mon Jun 20 09:34:08 2005 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 6C292528B2 for ; Mon, 20 Jun 2005 06:34:08 -0300 (ADT) 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 93795-08 for ; Mon, 20 Jun 2005 09:34:04 +0000 (GMT) Received: from twist.cefriel.it (twist.cefriel.it [131.175.53.12]) by svr1.postgresql.org (Postfix) with ESMTP id 6B9C45282C for ; Mon, 20 Jun 2005 06:34:02 -0300 (ADT) Received: from mail.cefriel.it ([131.175.53.10]) by twist.cefriel.it with Microsoft SMTPSVC(6.0.3790.211); Mon, 20 Jun 2005 11:33:51 +0200 Received: from mwlab07 ([10.10.4.25]) by mail.cefriel.it with Microsoft SMTPSVC(6.0.3790.211); Mon, 20 Jun 2005 11:33:51 +0200 From: "Luca Rasconi" To: Cc: Subject: FW: help with serial Date: Mon, 20 Jun 2005 11:33:51 +0200 Message-ID: <000901c5757b$2b3b7030$19040a0a@cefriel.it> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_000A_01C5758B.EEC44030" X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.2627 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 Importance: Normal X-OriginalArrivalTime: 20 Jun 2005 09:33:51.0662 (UTC) FILETIME=[2B3AACE0:01C5757B] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.253 tagged_above=0 required=5 tests=AWL, HTML_90_100, HTML_MESSAGE X-Spam-Level: X-Archive-Number: 200506/250 X-Sequence-Number: 21851 This is a multi-part message in MIME format. ------=_NextPart_000_000A_01C5758B.EEC44030 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hi all, There's a behaviour I can't understand!!!! There is table TABLE_A with 3 columns (uid, id, session) where uid is the pk and the data type is serial. There is table TABLE_B with 3 columns (uid, ts_col, col) where uid is the pk. On table TABLE_A I have a rule on insert like this: CREATE OR REPLACE RULE r1 AS ON INSERT TO TABLE_A DO INSERT INTO TABLE_B (uid) VALUES ((new.uid)); Till now. ok. When I do an insert insert into TABLE_A ("id", "session") values (7, 'aaaaaaaaaaaaa'); I have this row, In table TABLE_A 37; 7; "aaaaaaaaaaaaa" while in table TABLE_B 38; ""; "" how is it possible, why in a table 37 and in the other 37 + 1? Thank you, Luca ------=_NextPart_000_000A_01C5758B.EEC44030 Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Hi = all,

There’s a behaviour I can’t = understand!!!!

There is table TABLE_A with 3 columns (uid, id, = session) where uid is the pk and the data type is = serial.

There is table TABLE_B with 3 columns (uid, ts_col, = col) where uid is the pk.

 

On table TABLE_A I have a rule on insert like = this:

 

CREATE OR REPLACE RULE r1 = AS

    = ON INSERT TO TABLE_A DO  = INSERT INTO TABLE_B (uid)

  VALUES ((new.uid));

 

Till now… = ok…

When I do an insert

insert into TABLE_A ("id", = "session") values (7, 'aaaaaaaaaaaaa');

 

I have this row,

In table TABLE_A

37; 7; = "aaaaaaaaaaaaa"

 

while in table TABLE_B

38; ""; = ""

 

how is it possible, why in a table 37 and in the = other 37 + 1?

 

Thank you,

Luca

 

 

 

------=_NextPart_000_000A_01C5758B.EEC44030-- From dev@archonet.com Mon Jun 20 10:15:32 2005 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 C9034528B2 for ; Mon, 20 Jun 2005 07:15:32 -0300 (ADT) 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 02550-03 for ; Mon, 20 Jun 2005 10:15:24 +0000 (GMT) Received: from mail.metronet.co.uk (mail.metronet.co.uk [213.162.97.75]) by svr1.postgresql.org (Postfix) with ESMTP id 60ACC528B1 for ; Mon, 20 Jun 2005 07:15:23 -0300 (ADT) Received: from mainbox.archonet.com (84-51-143-99.archon037.adsl.metronet.co.uk [84.51.143.99]) by smtp.metronet.co.uk (MetroNet Mail) with ESMTP id 0B8F1417AF2; Mon, 20 Jun 2005 11:15:19 +0100 (BST) Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id CB96415EDB; Mon, 20 Jun 2005 11:10:42 +0100 (BST) Received: from mainbox.archonet.com ([127.0.0.1]) by localhost (mainbox [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 13229-03; Mon, 20 Jun 2005 11:10:39 +0100 (BST) Received: from [192.168.1.17] (client17.office.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id B2D7715F00; Mon, 20 Jun 2005 11:10:10 +0100 (BST) Message-ID: <42B69602.4050309@archonet.com> Date: Mon, 20 Jun 2005 11:10:10 +0100 From: Richard Huxton User-Agent: Mozilla Thunderbird 1.0.2 (X11/20050317) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Luca Rasconi Cc: pgsql-sql@postgresql.org Subject: Re: FW: help with serial References: <000901c5757b$2b3b7030$19040a0a@cefriel.it> In-Reply-To: <000901c5757b$2b3b7030$19040a0a@cefriel.it> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.054 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200506/254 X-Sequence-Number: 21855 Luca Rasconi wrote: > > CREATE OR REPLACE RULE r1 AS > ON INSERT TO TABLE_A DO INSERT INTO TABLE_B (uid) > VALUES ((new.uid)); > how is it possible, why in a table 37 and in the other 37 + 1? This is almost certainly the "nextval() evaluated twice" issue that catches everyone out from time to time. Check the mailing-list archives for discussion - it's because the rule acts as a macro, duplicating the expression. -- Richard Huxton Archonet Ltd