Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLFLf-0006jD-EL for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 22:33:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gLFLc-0007jB-U2 for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 22:33:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLFLc-0007e8-JJ for pgsql-hackers@lists.postgresql.org; Fri, 09 Nov 2018 22:33:52 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gLFLZ-0002fL-UX for pgsql-hackers@lists.postgresql.org; Fri, 09 Nov 2018 22:33:51 +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 wA9MXd18029153; Fri, 9 Nov 2018 17:33:39 -0500 From: Tom Lane To: Alvaro Herrera cc: =?utf-8?Q?J=C3=BCrgen?= Strobel , Amit Langote , Amit Langote , Ashutosh Bapat , PostgreSQL Hackers Subject: Re: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation In-reply-to: <20181109170712.pfn55lab5j7oae4v@alvherre.pgsql> References: <20181109170712.pfn55lab5j7oae4v@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Fri, 09 Nov 2018 14:07:12 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <29151.1541802819.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Fri, 09 Nov 2018 17:33:39 -0500 Message-ID: <29152.1541802819@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2018-Nov-09, Jürgen Strobel wrote: >> Regarding your example, what I expected is that *both* inserts would >> consistently result in a tuple of (1, 42) since p should route the >> insert to p1 and use p1's defaults. The current inconsistent behavior is >> the heart of the bug. > I think that would be sensible behavior, as long as the partition > doesn't override values for the partitioning column -- i.e. if the > default values don't re-route the tuple to another partition, I think we > should use the partition's default rather than the parent. This says we > should expand defaults after routing. I'd argue not, actually. I think there is plausible precedent in updatable views, where what we use is the defaults associated with the view, not the underlying table. Correspondingly, what ought to govern in a partitioned insert is the defaults associated with the table actually named in the insert command, never mind what its partitions might say. That is useful for many situations, and it avoids all the logical inconsistencies you get into if you find that the defaults associated with some partition would force re-routing elsewhere. In any case, you can't make this happen without basically blowing up default processing altogether. Defaults are currently expanded by the planner, and pretty early too. To make it work like the OP wishes, we'd have to insert them sometime late in the executor. > In any case it seems really hard to see this is as a bug that we would > fix in back-branches. Backwards compatibility considerations would prevent that in any case. regards, tom lane