Atomar SQL Statement - Mailing list pgsql-sql

From Weber, Johann (ISS Kassel)
Subject Atomar SQL Statement
Date
Msg-id B8ADDBDA8696F546BDAC69B469D7F0512E06F3@kasmaiexcp01.iss.net
Whole thread Raw
Responses Re: Atomar SQL Statement
List pgsql-sql
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



pgsql-sql by date:

Previous
From: Achilleus Mantzios
Date:
Subject: Re: Alternative to serial primary key
Next
From: Richard Huxton
Date:
Subject: Re: Alternative to serial primary key