Practical question. - Mailing list pgsql-general

From louis gonzales
Subject Practical question.
Date
Msg-id 45FA0BAA.9030606@linuxlouis.net
Whole thread Raw
In response to Re: Role & User - Inheritance?  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Practical question.  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Practical question.  (Ron Johnson <ron.l.johnson@cox.net>)
Re: Practical question.  ("hubert depesz lubaczewski" <depesz@gmail.com>)
List pgsql-general
Hello List,
I want to write a statement-level trigger - one that happens once per
statement - such that, immediately after an insert into a table(which
gets a unique integer value as an ID from a defined sequence, being the
primary key on the table), a new table is created with foreign key
constraint on that unique ID.
My concern is with what happens if two such inserts occur at almost the
same time, what is the best way to ensure that I never miss the creation
of one of the tables due to the 2nd one, possibly reading the same "max"
or nextvalue that the immediate previous trigger read.

As an example:
insertX which initiates the trigger reads the 'nextvalue' from the
sequence and begins to create the associcated table
insertY happens almost at the same time, so that it gets the same
'nextvalue' from the sequence and would then create or attempt to create
the 'same' assoicated table while missing it's 'true' 'nextvalue'.

Thanks for any insight!


--
Email:    louis.gonzales@linuxlouis.net
WebSite:  http://www.linuxlouis.net
"Open the pod bay doors HAL!" -2001: A Space Odyssey
"Good morning starshine, the Earth says hello." -Willy Wonka


pgsql-general by date:

Previous
From: Randall Smith
Date:
Subject: Re: pre-parser query manipulation
Next
From: Tom Lane
Date:
Subject: Re: pre-parser query manipulation