Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bSnSm-0004cF-EL for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 15:43:08 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bSnSl-0006Kx-Nt for pgsql-bugs@arkaria.postgresql.org; Thu, 28 Jul 2016 15:43:07 +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 1bSnSk-0006Ij-H7 for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 15:43:06 +0000 Received: from mail-lf0-x22a.google.com ([2a00:1450:4010:c07::22a]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bSnSh-0006ec-7D for pgsql-bugs@postgresql.org; Thu, 28 Jul 2016 15:43:06 +0000 Received: by mail-lf0-x22a.google.com with SMTP id f93so52518737lfi.2 for ; Thu, 28 Jul 2016 08:43:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=WSFpES/uLC3PIC7JS5qVyvsaX1zPmxHwTzyXXmZPFng=; b=g2vWzcuEBpW2nKt9c0UP5xYip14+vm5K+jnWCuqxr/CuPmcX2KKoBGsMNUU+YA6D75 4tDAYgkwOK5w6sTlW+oe0S8CsRMA00i3s5TRDLhkWSWi1v7lvFTlAw4H5RcqPGaklIe4 LWKgjfoWFiTCXIUIIfLQuLKvKI/pVxb2BdMD1msw66BkwhbSg4P9GXa0R0c+rP7TYEHp qbbFHSe2xhDpWtnuxMskzEWV38BnlNhs1BGlsE3xcJnKwum8a7RDnJO9fLluz21xQiSF 2F0mpoAhYDZr+cx7dJBHR1d/mgpth5sYC8go4w9J5r6PrdWi4Ym2SaKLoDlIjUZ1c0ft PnDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=WSFpES/uLC3PIC7JS5qVyvsaX1zPmxHwTzyXXmZPFng=; b=UVR36qOEhT4gyP8CdPrvoxUtapBxCm+7CebnCeK7fRKwF9YoQvvxH1BevKVlKTqrUZ uwMTif08AY+KxAJtsNFrqpSEo4eGgeOS3zp/4jp0QUtzToXp8/5EfHtif0+eHjMuFiPn FoSHUnzAJZ/5r0ocqlWchpIf5KLSgaGLV3Z/iLuJ0Z9FyHZbzvuakzvjXj0hY7X+ynWn xYQjukliST/H4mXDpiFUt6MO5uxqCJ969CiRb6cMnMR3OigMcrsmzRqevt/H4SxLZO6Z HbioQOWBEpLGua1aMKNLPHd204vGz+6rPS/MMZwTcdohX/TKrfDu7zn2i+3WiYe9asba Qf4g== X-Gm-Message-State: AEkoouuTOfIhVhblBbeicepcZ2pHB0MrWjn8nTOX6utu60qtuyiQbMtMIe25mnplmI7LH1ch6d8nxxeL8sqSpQ== X-Received: by 10.25.40.138 with SMTP id o132mr11938791lfo.221.1469720581483; Thu, 28 Jul 2016 08:43:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.25.1.205 with HTTP; Thu, 28 Jul 2016 08:43:00 -0700 (PDT) In-Reply-To: <20160728151154.AABE64016B@smtp.hushmail.com> References: <20160728151154.AABE64016B@smtp.hushmail.com> From: Vitaly Burovoy Date: Thu, 28 Jul 2016 08:43:00 -0700 Message-ID: Subject: Re: bug error message constraint "con_item_id_costelement" for table "costs" does not exist SQL state: 42704 To: joel.traf@magwerks.com Cc: pgsql-bugs@postgresql.org Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.7 (--) 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 On 7/28/16, joel.traf@magwerks.com wrote: > 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); You have there columns which are present neither in xmag.costs nor in costs. 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" > insert into costs (select * from costs); The command above does nothing since "costs" has just been creates and has nothing. > 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 Here you can use columns of index, e.g: ON CONFLICT (cost_item_id, cost_costelem_id) DO UPDATE > 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; > -- Best regards, Vitaly Burovoy -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs