pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedFW: help with serial
2+ messages / 2 participants
[nested] [flat]
* FW: help with serial
@ 2005-06-20 09:33 Luca Rasconi <luca.rasconi@students.cefriel.it>
0 siblings, 1 reply; 2+ messages in thread
From: Luca Rasconi @ 2005-06-20 09:33 UTC (permalink / raw)
To: pgsql-sql; +Cc: luca.rasconi@students.cefriel.it
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
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: FW: help with serial
@ 2005-06-20 10:10 Richard Huxton <dev@archonet.com>
parent: Luca Rasconi <luca.rasconi@students.cefriel.it>
0 siblings, 0 replies; 2+ messages in thread
From: Richard Huxton @ 2005-06-20 10:10 UTC (permalink / raw)
To: Luca Rasconi <luca.rasconi@students.cefriel.it>; +Cc: pgsql-sql
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2005-06-20 10:10 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-06-20 09:33 FW: help with serial Luca Rasconi <luca.rasconi@students.cefriel.it>
2005-06-20 10:10 ` Richard Huxton <dev@archonet.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox