Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSp3I-0000qM-K2 for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 17:24:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bSp3I-0008F6-6z for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 17:24:56 +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 1bSp0D-0005y3-Ub for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 17:21:45 +0000 Received: from smtp3.hushmail.com ([65.39.178.200]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bSp05-0008OE-Tm for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 17:21:44 +0000 Received: from smtp3.hushmail.com (localhost [127.0.0.1]) by smtp3.hushmail.com (Postfix) with SMTP id 2F1B1E02F0 for ; Thu, 28 Jul 2016 17:21:34 +0000 (UTC) X-hush-tls-connected: 1 Received: from smtp.hushmail.com (w9.hushmail.com [65.39.178.29]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp3.hushmail.com (Postfix) with ESMTPS; Thu, 28 Jul 2016 17:21:32 +0000 (UTC) Received: by smtp.hushmail.com (Postfix, from userid 99) id E29CE4010C; Thu, 28 Jul 2016 17:21:32 +0000 (UTC) MIME-Version: 1.0 Date: Thu, 28 Jul 2016 13:21:32 -0400 To: "Tom Lane" , "Vitaly Burovoy" Cc: pgsql-bugs@postgresql.org Subject: Re: bug error message constraint "con_item_id_costelement" for table "costs" does not exist SQL state: 42704 From: joel.traf@magwerks.com In-Reply-To: <19144.1469721911@sss.pgh.pa.us> References: <20160728151154.AABE64016B@smtp.hushmail.com> <19144.1469721911@sss.pgh.pa.us> Content-Type: multipart/alternative; boundary="=_28e06a1a23688595cd9744001ff677b2" Message-Id: <20160728172132.E29CE4010C@smtp.hushmail.com> X-Pg-Spam-Score: -2.6 (--) 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 --=_28e06a1a23688595cd9744001ff677b2 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="UTF-8" Hi Tom Thanks for the answer that explains things. My i humbly suggest adding notes to the create table clone ( original including all). Stating the limitation on constraints not duplicating an identical name and code that depends on the "constraint name" aka Upsert will fail. Also suggest adding the same comment to the Insert on conflict stating. Tables that are cloned with (including all ) the constraint is not automatically recreated with the same name so the constraint needs to be manually re-created with that specific name for the temp table. Additionally could throw a notice that when a table is cloned with the copy indexes or constraints, stating names are not preserved and may cause issues with Upsert on conflict. again thanks On 7/28/2016 at 12:05 PM, "Tom Lane" wrote:Vitaly Burovoy writes: > On 7/28/16, joel.traf@magwerks.com wrote: >> The documentation states "create temp table mytable (including all) " >> is suppose to create all the constraints > CREATE TABLE ... (LIKE ...) > creates indexes and constraints with names as if they weren't given > (i.e. by default), so your > constraint "con_item_id_costelement" becomes > "costs_cost_item_id_cost_costelem_id_key" There's a comment in generateClonedIndexStmt about that: * We don't try to preserve the name of the source index; instead, just * let DefineIndex() choose a reasonable name. However, this isn't documented anywhere user-visible AFAICS, and it probably should be. It's rather annoying that LIKE doesn't duplicate names of constraints, especially now that we've invented ON CONFLICT and thereby made constraint names something that would be explicitly referenced in DML code. However, I'm afraid that doing so is harder than it looks because index names have to be unique within a schema. If we tried to copy constraint names we'd get a failure anytime the new table is in the same schema as the LIKE source table. regards, tom lane --=_28e06a1a23688595cd9744001ff677b2 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="UTF-8" Hi Tom

Thanks = for the answer that explains things. 

My i humbly suggest addi= ng notes to the create  table clone ( original including all).  S= tating the limitation on constraints not duplicating an identical name and = code that depends on the "constraint name" aka Upsert will fail.

Als= o suggest adding  the same comment to the Insert on conflict stating.&= nbsp; Tables that are cloned with (including all ) the constraint is not au= tomatically recreated with the same name so the constraint needs to be manu= ally re-created with that specific name for the temp table. 

<= br>Additionally could throw a notice that when a table is cloned with the c= opy indexes or constraints,  stating names are not preserved and may c= ause issues with Upsert on conflict.

again thanks


On 7/28= /2016 at 12:05 PM, "Tom Lane" <tgl@sss.pgh.pa.us> wrote:
Vit= aly Burovoy <vitaly.burovoy@gmail.com> writes:
> On 7/28/16, jo= el.traf@magwerks.com <joel.traf@magwerks.com> wrote:
>> The = documentation states "create temp table mytable (including all) "
>&g= t; is suppose to create all the constraints

> CREATE TABLE ... (L= IKE ...)
> creates indexes and constraints with names as if they were= n't given
> (i.e. by default), so your
> constraint "con_item_i= d_costelement" becomes
> "costs_cost_item_id_cost_costelem_id_key"
There's a comment in generateClonedIndexStmt about that:

* We= don't try to preserve the name of the source index; instead, just
* l= et DefineIndex() choose a reasonable name.

However, this isn't docum= ented anywhere user-visible AFAICS, and it
probably should be.

It= 's rather annoying that LIKE doesn't duplicate names of constraints,
esp= ecially now that we've invented ON CONFLICT and thereby made constraint
= names something that would be explicitly referenced in DML code. However,<= br>I'm afraid that doing so is harder than it looks because index names hav= e
to be unique within a schema. If we tried to copy constraint names we= 'd
get a failure anytime the new table is in the same schema as the LIKE=
source table.

regards, tom lane
--=_28e06a1a23688595cd9744001ff677b2--