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 1gL9vE-0007vX-EH for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 16:46:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gL9vC-0004oH-5P for pgsql-hackers@arkaria.postgresql.org; Fri, 09 Nov 2018 16:46:14 +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.89) (envelope-from ) id 1gL9vB-0004oA-Lw for pgsql-hackers@lists.postgresql.org; Fri, 09 Nov 2018 16:46:13 +0000 Received: from mail-wr1-x42e.google.com ([2a00:1450:4864:20::42e]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gL9v8-0002k2-St for pgsql-hackers@lists.postgresql.org; Fri, 09 Nov 2018 16:46:12 +0000 Received: by mail-wr1-x42e.google.com with SMTP id y15-v6so2576844wru.9 for ; Fri, 09 Nov 2018 08:46:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=strobel.info; s=google; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=8EHw5h9zdUbgag0rieiw97tc8XlmtA1gCWUXeZaaZio=; b=USH9G4SC4lrLdPi3hAhxnxu9+3IpetI0eCgf4sUNIYl6xENuySqJK5y+dREI4cPqDk Z5dGsPvPcALj5PXUaPDt7TdCD8A5AjVI5j2HnkxM5GHWrDegvsWBnlqFsKmMR3PS033l 7bXeF+0ki/zKf/XMlIRGHRQ13blz7amq/9d80= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=8EHw5h9zdUbgag0rieiw97tc8XlmtA1gCWUXeZaaZio=; b=q4AoH73hMZyGwU1BY7zq864iR+W5QxUugaGxUoGXumH/RrfLQNRuaqcVA6dih91ph9 1JI+pvJbRUslJUHP4pRm1yOKfkamRGkBQrMTj37muQLQK/6R1ORn8Wx05v3cMMekPi8S YrvZ+B06f2/4kLHCM9UwFfDZWaGbdi1yKhyXW45iP8gAK8+W7tFMBwl6w6rpqlqU/5Fe HrYlCL8R/Dad2ek+FowWte8o3CE8F7IWyD4FAqz4c4PgIpx0aIzpvXmDPqUJSCUiF+5s 0bR19tWeAYlD3gZx7tpJK3jggg740gnQLC+rIYjWSUwXH+38fgDd3OqwmlC9lUy2UtvV U73g== X-Gm-Message-State: AGRZ1gJDDD3xK3v+S6eRFCgNUrARdtuKCG1znKjdNte+UWFefQ8HkKkm SIHdQaRcye3RNvDo9a6nN94iSQ== X-Google-Smtp-Source: AJdET5cr4o4feMyoNc+653OvCNrcSRPamJ6pjiBYprVF1DPfWkZhl437+yOJldTnub3WWJdHWVQteQ== X-Received: by 2002:a5d:4cc6:: with SMTP id c6-v6mr9046850wrt.75.1541781969270; Fri, 09 Nov 2018 08:46:09 -0800 (PST) Received: from Juergens-MacBook.local (178.165.130.194.wireless.dyn.drei.com. [178.165.130.194]) by smtp.gmail.com with ESMTPSA id w2-v6sm7208643wre.57.2018.11.09.08.46.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Nov 2018 08:46:08 -0800 (PST) From: =?UTF-8?Q?J=c3=bcrgen_Strobel?= Subject: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation To: Alvaro Herrera , Amit Langote Cc: Amit Langote , Ashutosh Bapat , PostgreSQL Hackers , =?UTF-8?Q?J=c3=bcrgen_Strobel?= References: <20181109155943.xnlbcyzp7crnyjmo@alvherre.pgsql> Message-ID: <67125a48-0e0f-4f7e-6d02-e312fe13f7fe@strobel.info> Date: Fri, 9 Nov 2018 17:46:04 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20181109155943.xnlbcyzp7crnyjmo@alvherre.pgsql> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2018-11-09 16:59, Alvaro Herrera wrote: > On 2018-Nov-09, Amit Langote wrote: > >> Or is it a *bug* of tuple-routing that it doesn't substitute default >> values that may be defined for partitions? It kind of looks like one if >> you see an example like this. >> >> create table p (a int, b int) partition by list (a); >> create table p1 partition of p (b not null default 1) for values in (1); >> insert into p1 values (1); >> table p; >> a │ b >> ───┼─── >> 1 │ 1 >> (1 row) >> >> insert into p values (1); >> ERROR: null value in column "b" violates not-null constraint >> DETAIL: Failing row contains (1, null). > > I don't know. I wonder if the bug isn't that we allow the default to be > specified for the partition at all -- why shouldn't we just reject that > with an error? > > See this example, where the inserts give values that could be said to be > inconsistent: > > create table p (a int , b int default 3) partition by list (a); > create table p1 partition of p (b default 42) for values in (1); > insert into p (a) values (1); > insert into p1 (a) values (1); > select * from p; > > a │ b > ───┼──── > 1 │ 3 > 1 │ 42 > (2 filas) I found this problem while attempting to create sub-ids with partition defaults using distinct per-partition sequences. I can think of other useful scenarios too, but if you don't want to support it because of unexpected complexities all my cases can still be implemented using custom triggers albeit slower and more inconvenient. 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. Best regards, Jürgen