Re: INSERT WHERE NOT EXISTS

Поиск
Список
Период
Сортировка
От DeJuan Jackson
Тема Re: INSERT WHERE NOT EXISTS
Дата
Msg-id 3EFCCF08.7070702@speedfc.com
обсуждение исходный текст
Ответ на Re: INSERT WHERE NOT EXISTS  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Ответы Re: INSERT WHERE NOT EXISTS  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Список pgsql-general
Karsten Hilbert wrote:
// check if entry already exists
SELECT COUNT(*) FROM tablename WHERE [cond]   
You may want to try this instead:
select exists(select * from tablename where [cond])

which should be faster than count(*). You'll get back a
boolean value, though, not an integer.

Karsten 
Why not do:
 SELECT 1 FROM tablename WHERE [cond];

  And use row_count > 0 to determine a hit.

And I can't think of a way to prevent the race-condition thing besides using SERIALIZABLE ISOLATION.

В списке pgsql-general по дате отправления:

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: Redhat's "enhancements" to PG
Следующее
От: Karsten Hilbert
Дата:
Сообщение: Re: INSERT WHERE NOT EXISTS