Re: BUG #14791: Error 42P07 but the relation DOESN'T Exists! Error 42P01

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: jfblazquez(dot)ayesa(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14791: Error 42P07 but the relation DOESN'T Exists! Error 42P01
Date: 2017-08-30 17:56:51
Message-ID: 17465.1504115811@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

jfblazquez(dot)ayesa(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2017-08-30 18:16:14 Re: [HACKERS] [postgresql 10 beta3] unrecognized node type: 90
Previous Message zosrothko 2017-08-30 17:39:50 BUG #14792: Invalid ssleay32.dll