Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dn7FI-0003Hw-Ef for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Aug 2017 17:57:44 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dn7FI-0000G1-1X for pgsql-bugs@arkaria.postgresql.org; Wed, 30 Aug 2017 17:57:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dn7Ea-0007QX-RB for pgsql-bugs@postgresql.org; Wed, 30 Aug 2017 17:57:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dn7ET-0004jK-LV for pgsql-bugs@postgresql.org; Wed, 30 Aug 2017 17:57:00 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v7UHupRZ017466; Wed, 30 Aug 2017 13:56:51 -0400 From: Tom Lane To: jfblazquez.ayesa@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14791: Error 42P07 but the relation DOESN'T Exists! Error 42P01 In-reply-to: <20170830154553.1708.34801@wrigleys.postgresql.org> References: <20170830154553.1708.34801@wrigleys.postgresql.org> Comments: In-reply-to jfblazquez.ayesa@gmail.com message dated "Wed, 30 Aug 2017 15:45:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <17464.1504115811.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Wed, 30 Aug 2017 13:56:51 -0400 Message-ID: <17465.1504115811@sss.pgh.pa.us> List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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