From: Weber, Johann (ISS Kassel) <jweber@iss.net>
To: pgsql-sql@postgresql.org
Subject: Atomar SQL Statement
Date: Fri, 7 Jul 2006 13:55:02 +0200
Message-ID: <B8ADDBDA8696F546BDAC69B469D7F0512E06F3@kasmaiexcp01.iss.net> (raw)
Guys,
I want to assure that a SQL statement is atomar. It trys to check if an
email address is already found in a table, if yes, it returns the id
field of the entry. If not found, it inserts the entry with the
previously generated increment id and returns - again - the id.
My concern: in a multi threaded environment, can a second thread
interrupt this statement and eventually insert the same email address in
the table with a different id? Or is this statement atomar?
Any help would be highely appreciated.
CODE:
_id := nextval('email_id_increment');
INSERT INTO email_adr (email_id, email, lastupdate)
SELECT _id, 'sender@example.com', now()::timestamp
WHERE NOT EXISTS (SELECT * FROM email_adr WHERE
email='sender@example.com');
- Johann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jweber@iss.net
Subject: Re: Atomar SQL Statement
In-Reply-To: <B8ADDBDA8696F546BDAC69B469D7F0512E06F3@kasmaiexcp01.iss.net>
References: <B8ADDBDA8696F546BDAC69B469D7F0512E06F3@kasmaiexcp01.iss.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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