Atomar SQL Statement

Поиск
Список
Период
Сортировка
От Weber, Johann (ISS Kassel)
Тема Atomar SQL Statement
Дата
Msg-id B8ADDBDA8696F546BDAC69B469D7F0512E06F3@kasmaiexcp01.iss.net
обсуждение исходный текст
Ответы Re: Atomar SQL Statement
Список 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 по дате отправления:

Предыдущее
От: Achilleus Mantzios
Дата:
Сообщение: Re: Alternative to serial primary key
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: Alternative to serial primary key