Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists" - Mailing list pgsql-bugs

From Andy S
Subject Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"
Date
Msg-id CAFAcjJOCE=TCeiRX_=2qKzHkLiQjhqmzVk9XeAHEXBDH8Erq3A@mail.gmail.com
Whole thread Raw
In response to Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Fri, Dec 4, 2020 at 8:30 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
IF NOT EXISTS doesn't attempt to be bulletproof: it just checks at the
start of the command to see if the object name is already there.  So
it's not sufficient to guard concurrent creations.  You can call that
a bug if you like, but it's quite unlikely to change anytime soon.

This is then at least a documentation bug since docs provide less information for the user then it's needed to properly decide on strategy.
 
You might consider using advisory locks [1] to keep your various sessions
from trying to do this at the exact same time.

Thanks, I'll update the DDLs to wrap the queries emitted with those locks. 

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"
Next
From: Tom Ellis
Date:
Subject: Small query yields "error: no relation entry for relid 11"