pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: jfblazquez.ayesa@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14791: Error 42P07 but the relation DOESN'T Exists! Error 42P01
Date: Wed, 30 Aug 2017 13:56:51 -0400
Message-ID: <17465.1504115811@sss.pgh.pa.us> (raw)
In-Reply-To: <20170830154553.1708.34801@wrigleys.postgresql.org>
References: <20170830154553.1708.34801@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

jfblazquez.ayesa@gmail.com writes:
> TEST=# CREATE TABLE scada_equipment_instance
> ...
> TEST(#   CONSTRAINT scada_equipment_instance UNIQUE
> ...
> ERROR:  la relación «scada_equipment_instance» ya existe

The problem here is that that unique constraint has to have an underlying
index, and the index will be named the same as the constraint, causing it
to collide with the table name.  So this error is really coming from
the implied CREATE INDEX command: it sees a conflicting relation name
already in place.  After the whole command rolls back, of course you
have no table either, so this is unsurprising:

> TEST=# ALTER TABLE scada_equipment_instance
> TEST-#   OWNER TO postgres;
> ERROR:  no existe la relación «scada_equipment_instance»

Short answer is that unique/pkey constraints can't be named the same as
any table in the same schema.  Personally I'd leave off the "CONSTRAINT
name" part altogether and let the system pick a nonconflicting index name.

(Not sure that our documentation is sufficiently clear on this.
Since it's not really what you'd expect from reading the SQL standard,
maybe we need to mention it in more places than we do now.)

			regards, tom lane


-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (3+ messages)  latest in thread

Message-ID: <17465.1504115811@sss.pgh.pa.us>
Permalink:  ../17465.1504115811@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17465.1504115811@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, jfblazquez.ayesa@gmail.com
  Subject: Re: BUG #14791: Error 42P07 but the relation DOESN'T Exists! Error 42P01
  In-Reply-To: <17465.1504115811@sss.pgh.pa.us>
  References: <20170830154553.1708.34801@wrigleys.postgresql.org> <17465.1504115811@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox