Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSn4b-0003M0-MZ for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 15:18:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bSn4b-0001oz-9A for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 15:18:09 +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 1bSmyq-0006Qb-NG for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 15:12:12 +0000 Received: from smtp1.hushmail.com ([65.39.178.135]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bSmye-00066x-3p for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 15:12:11 +0000 Received: from smtp1.hushmail.com (localhost [127.0.0.1]) by smtp1.hushmail.com (Postfix) with SMTP id E69EE40A67 for ; Thu, 28 Jul 2016 15:11:55 +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 smtp1.hushmail.com (Postfix) with ESMTPS; Thu, 28 Jul 2016 15:11:54 +0000 (UTC) Received: by smtp.hushmail.com (Postfix, from userid 99) id AABE64016B; Thu, 28 Jul 2016 15:11:54 +0000 (UTC) MIME-Version: 1.0 Date: Thu, 28 Jul 2016 11:11:54 -0400 To: pgsql-bugs@postgresql.org Subject: bug error message constraint "con_item_id_costelement" for table "costs" does not exist SQL state: 42704 From: joel.traf@magwerks.com Content-Type: multipart/alternative; boundary="=_ee554afdf0a733119db981a1209a3e80" Message-Id: <20160728151154.AABE64016B@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 --=_ee554afdf0a733119db981a1209a3e80 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="UTF-8" Hello PostgreSQL Developers Ran into a bug or issue with the documentation where creating a TEMP table fails to create all the constraints and Upsert fails on check constraint The documentation states "create temp table mytable (including all) " is suppose to create all the constraints https://www.postgresql.org/docs/9.5/static/sql-createtable.html below is the the code to duplicate this issue. I was able to work around the issue by adding the needed constraint below the create temp command. select version() result: "PostgreSQL 9.5.0, compiled by Visual C++ build 1800, 64-bit" ---code to create error. CREATE TABLE xmag.costs ( cost_id serial primary key, cost_item_id integer NOT NULL, cost_costelem_id integer NOT NULL, cost_lowlevel boolean NOT NULL DEFAULT false, cost_stdcost numeric(24,8) NOT NULL DEFAULT 0, cost_posted date, cost_actcost numeric(24,8) NOT NULL DEFAULT 0, cost_updated date, CONSTRAINT con_item_id_costelement UNIQUE (cost_item_id, cost_costelem_id) ); insert into xmag.costs values (12083,12210,3,FALSE,16.95000000,'2014-03-25',16.95000000,'2014-03-25'), (12084,12211,3,FALSE,6.27000000,'2014-03-25',6.27000000,'2014-03-25'), (12085,12212,3,FALSE,35.36000000,'2014-03-25',35.36000000,'2014-03-25'), (12088,12215,3,FALSE,31.50000000,'2013-10-25',31.50000000,'2014-07-31'), (12089,12216,3,FALSE,0.64000000,'2013-06-27',0.64000000,'2014-07-31'), (12090,12217,3,FALSE,0.00000000,'2013-06-27',0.00000000,'2014-07-31'); create temp table costs ( like xmag.costs including all ); --commented out to show bug --ALTER TABLE public.itemcost --ADD CONSTRAINT con_item_id_itemcostelement UNIQUE(itemcost_item_id, itemcost_costelem_id); insert into costs (select * from costs); Insert into costs values (default,12210,3,FALSE,16.95000000,'2014-03-25',16.95000000,'2014-03-25') on conflict on constraint con_item_id_costelement do update set cost_actcost = matcost, cost_updated = now()::Date, cost_posted = now()::date, cost_stdcost = 10 where cost_item_id= 12210 and costs.cost_costelem_id = 3; --=_ee554afdf0a733119db981a1209a3e80 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset="UTF-8" Hello  PostgreSQL= Developers

Ran into a bug or issue with the documentation  whe= re creating a TEMP table fails to create all the constraints and = Upsert fails on check constraint

The documentation states "crea= te temp table mytable (including all) "  is suppose to create all the = constraints
https://www.postgresql.org/docs/9.5/static/sql-createtable= .html

below is the  the code to duplicate this issue.
I was able to work around the issue by adding the needed constraint below= the create temp command. 

select version() result: "PostgreSQ= L 9.5.0, compiled by Visual C++ build 1800, 64-bit"

---code to creat= e error.  

CREATE TABLE xmag.costs
(
  cost_id seri= al primary key,
  cost_item_id integer NOT NULL,
  cost_cos= telem_id integer NOT NULL,
  cost_lowlevel boolean NOT NULL DEFAULT= false,
  cost_stdcost numeric(24,8) NOT NULL DEFAULT 0,
  = cost_posted date,
  cost_actcost numeric(24,8) NOT NULL DEFAULT 0,<= br>  cost_updated date,
  CONSTRAINT con_item_id_costelement U= NIQUE (cost_item_id, cost_costelem_id)
);

insert into xmag.costs = values
(12083,12210,3,FALSE,16.95000000,'2014-03-25',16.95000000,'2014-= 03-25'),
(12084,12211,3,FALSE,6.27000000,'2014-03-25',6.27000000,'2014-0= 3-25'),
(12085,12212,3,FALSE,35.36000000,'2014-03-25',35.36000000,'2014-= 03-25'),
(12088,12215,3,FALSE,31.50000000,'2013-10-25',31.50000000,'2014= -07-31'),
(12089,12216,3,FALSE,0.64000000,'2013-06-27',0.64000000,'2014-= 07-31'),
(12090,12217,3,FALSE,0.00000000,'2013-06-27',0.00000000,'2014-0= 7-31');


create temp table costs ( like xmag.costs including all&= nbsp; );
--commented out to show bug
--ALTER TABLE public.itemcost--ADD CONSTRAINT con_item_id_itemcostelement UNIQUE(itemcost_item_id, ite= mcost_costelem_id);

insert into costs (select * from costs);

Insert into costs
    values
   =     (default,12210,3,FALSE,16.95000000,'2014-03-25',16.9500= 0000,'2014-03-25')
    on conflict on constraint con_item= _id_costelement  
    do update set cost_actcost =3D= matcost, cost_updated =3D now()::Date,
      =  cost_posted =3D  now()::date,
     &nbs= p;  cost_stdcost =3D 10
        where= cost_item_id=3D 12210 and costs.cost_costelem_id =3D 3;
--=_ee554afdf0a733119db981a1209a3e80--