Re: INSERT WHERE NOT EXISTS - Mailing list pgsql-general

From DeJuan Jackson
Subject Re: INSERT WHERE NOT EXISTS
Date
Msg-id 3EFCCF08.7070702@speedfc.com
Whole thread Raw
In response to Re: INSERT WHERE NOT EXISTS  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
Responses Re: INSERT WHERE NOT EXISTS  (Karsten Hilbert <Karsten.Hilbert@gmx.net>)
List 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 by date:

Previous
From: Ron Johnson
Date:
Subject: Re: Redhat's "enhancements" to PG
Next
From: Karsten Hilbert
Date:
Subject: Re: INSERT WHERE NOT EXISTS