Re: race conditions in my sequences - Mailing list pgsql-general

From Gregory Wood
Subject Re: race conditions in my sequences
Date
Msg-id 019801c12687$03b79d50$7889ffcc@comstock.com
Whole thread Raw
In response to race conditions in my sequences  (Jeremy Hansen <jeremy@xxedgexx.com>)
List pgsql-general
> Any suggestions would be more then appreciate as always.  Is there a
> better way to do what I'm trying to do?

I would recommend using only one sequence for the master table. Then just
reference that sequence value for the two foreign keys. For example:

BEGIN;
INSERT INTO Bugs (bug_date) VALUES (CURRENT_DATE);
INSERT INTO BugA (bug_id,bug_desc) VALUES (currval('bugs_bug_id_seq'),'This
is a bug');
INSERT INTO BugB (bug_id,bug_fix) VALUES (currval('bugs_bug_id'),'Reinstall
Windows... again');
COMMIT;

This way, you don't have to worry about sequences getting out of sync
because they all refer to the same value.

As for the timestamp problem... I don't know how you are trying to INSERT
those values (interface, SQL, etc).

Greg



pgsql-general by date:

Previous
From: "Ben-Nes Nimrod"
Date:
Subject: unix timestamp
Next
From: Tigran
Date:
Subject: Win2K install