Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bq3Lx-00085p-KB for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Sep 2016 19:20:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bq3Lx-0005SK-69 for pgsql-bugs@arkaria.postgresql.org; Fri, 30 Sep 2016 19:20:13 +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 1bq3LI-0003oG-5V for pgsql-bugs@postgresql.org; Fri, 30 Sep 2016 19:19:32 +0000 Received: from mail-yb0-x22f.google.com ([2607:f8b0:4002:c09::22f]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bq3LE-0000tF-Fq for pgsql-bugs@postgresql.org; Fri, 30 Sep 2016 19:19:31 +0000 Received: by mail-yb0-x22f.google.com with SMTP id z8so31611935ybh.3 for ; Fri, 30 Sep 2016 12:19:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:reply-to:subject:references:to:cc:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=5pax3bmtS0lvyAEcikpg7Ci2u5TteXkytcHQAitb4DY=; b=vMNUP3xbfNnxsVbdQO3fGFwOJKDzHJxy1KF/A/NSIsM/piJXv8kvAj+FBvbnJYOVCv /SDQWwOgxXPLTNTjmAPAN+fphRSSqL4LMfODKjRaWcFwyuJPhcEMts3beDmCT2ZirOG5 51CYS5NglUN42ch92VlH0q2z9O1BrxQupL5LOdjaJc1REDQM6zTw+S0IxxYBJylkPMMD yPhvkWlVh9X1PUvUTP6kHtAw7VFxxDmDrQltkziDEHtFpJ+rU6SmGCgMdTtvgbufuYwQ bgLGNJN4N5Vo7K+r4c42dY74Wg2RYjOwYZYp+yUdylJAOvUwGowqEgfRPBO2JnswPf6u kWTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:reply-to:subject:references:to:cc :message-id:date:user-agent:mime-version:in-reply-to :content-transfer-encoding; bh=5pax3bmtS0lvyAEcikpg7Ci2u5TteXkytcHQAitb4DY=; b=Hjk4DSm2yKmHzKtd4FCV4vnum4jhKq0LhFRaUstgctHEyETXKwbJ+MuzuKrlov5Lx1 d7LoNk7/HydxCZS39L3KBZgEyq/Mavos3StNYxonusaOova3LAqUD7G5HiNNuxIMH6TP wX9DVk7QycWxFCF8Nl9pcqm3W99JYg1gyLcCpSzXEvl9faQqm7MPrfSQXHWLZ8dvKIHX 4gQEhCCIeUkz5wr6vgou0InsocLPKaYZeD0TIchNuaQg6dw9sMvNjc+hYm4c8NyHlJwi XcbtuwXbD95TjCXIZHR94kK6ieoqajBW6t+ZNDPH9a2+zDI00+PYe6dbx52EfpfxwOyj m01A== X-Gm-Message-State: AA6/9RmikUzkGPAxTF6dQBOTpyJDvylR7ProuyrY5Qb/gDpYvLlTQsXvA6Z3hCwFfd/afQ== X-Received: by 10.37.162.42 with SMTP id b39mr5996540ybi.53.1475263166836; Fri, 30 Sep 2016 12:19:26 -0700 (PDT) Received: from [127.0.0.1] ([66.171.85.153]) by smtp.gmail.com with ESMTPSA id a67sm9527420ywe.39.2016.09.30.12.19.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Sep 2016 12:19:26 -0700 (PDT) From: Reyes Ponce X-Google-Original-From: Reyes Ponce Reply-To: Reyes.R.Ponce@gmail.com Subject: Re: BUG #14343: UPSERT (ON CONFLICT) doesn't check ON CONFLICT constraint first References: <20160927175223.20214.60920@wrigleys.postgresql.org> <29583.1475003191@sss.pgh.pa.us> To: Tom Lane Cc: pgsql-bugs@postgresql.org Message-ID: <52f8c8f5-5f31-cac4-fd43-a84d464bd23c@gmail.com> Date: Fri, 30 Sep 2016 15:19:38 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <29583.1475003191@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Antivirus: avast! (VPS 160930-0, 09/30/2016), Outbound message X-Antivirus-Status: Clean X-Pg-Spam-Score: -2.0 (--) 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 Hi Tom, That may be "the design" and it may be a fine design for insert, but it's not a great design for upsert, which was sort of my point. An update statement does not require all NOT NULL columns to be specified so neither should an upsert require all NOT NULL columns to be specified in the case where the update will run. Any chance you guys will do a UPDATE ... ON MISSING... DO INSERT... version as I expect in that case it would be implemented closer to the functionality you get implementing upsert with a CTE (and how upsert in most NoSql DB works (i.e. doesn't impose more restrictions than update in the update case)) which would cover far more use cases than the current design of INSERT... ON CONFLICT... DO UPDATE...? Thanks for all the hard work. I've only been using Postgres for a few months, but thus far it's been solid. -- Reyes On 9/27/2016 3:06 PM, Tom Lane wrote: > reyes.r.ponce@gmail.com writes: >> ERROR: null value in column "col1" violates not-null constraint >> DETAIL: Failing row contains (1, null, 5, 2016-09-27 17:32:51.054896+00, >> pl_mstr_usr, 2016-09-27 17:32:51.054896+00, pl_mstr_usr). >> CONTEXT: SQL statement "INSERT INTO public.MyTable( >> MY_ID, COL1, COL2, CRETN_TS, CRETN_USER_ID, UPDT_TS, >> UPDT_USER_ID) >> VALUES ($1, $2, $3, NOW(), current_user, NOW(), current_user) >> ON CONFLICT(MY_ID) >> DO UPDATE SET UPDT_TS = NOW(), UPDT_USER_ID = current_user, COL2 = $3" >> PL/pgSQL function upsert_mytable(integer,integer,integer) line 46 at >> EXECUTE > This test case seems rather overcomplicated, but AFAICS you are > complaining because the NOT NULL constraint is checked before uniqueness > is checked. Sorry, that is not a bug, that is by design. > > 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