Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"

From: Andy S <gatekeeper(dot)mail(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"
Date: 2020-12-04 17:43:38
Message-ID: CAFAcjJOCE=TCeiRX_=2qKzHkLiQjhqmzVk9XeAHEXBDH8Erq3A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Fri, Dec 4, 2020 at 8:30 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Ellis 2020-12-05 17:30:56 Small query yields "error: no relation entry for relid 11"
Previous Message Tom Lane 2020-12-04 17:30:06 Re: BUG #16763: CREATE TABLE IF NOT EXISTS fails with "relation exists"