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 1gK2zr-0006CI-Qf for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Nov 2018 15:10:28 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gK2zq-000471-8j for pgsql-hackers@arkaria.postgresql.org; Tue, 06 Nov 2018 15:10:26 +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 1gK2zp-00046m-TQ for pgsql-hackers@lists.postgresql.org; Tue, 06 Nov 2018 15:10:26 +0000 Received: from mail-qt1-x842.google.com ([2607:f8b0:4864:20::842]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gK2zi-0000TW-Lf for pgsql-hackers@lists.postgresql.org; Tue, 06 Nov 2018 15:10:25 +0000 Received: by mail-qt1-x842.google.com with SMTP id z20-v6so2925619qti.9 for ; Tue, 06 Nov 2018 07:10:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=e+MJEyxmfK4Sv4lL3PFYCtYbhoyBCwTdEWICmQEy0YI=; b=g8gQak9XGNX3p4B9RtsJGvRLW5K5LnBb//J+QqgJxakUp3kt/AdaaDqil8ls6ZuuRG ZYFQPQipLGZlcQho4c4WkKJQiY9OfUxr+YUVrwQFMOdKsdKFrrEbkzTDe0d3wFpP6w/N gd/hTA79kwP+564kkyRquqiXHtufUR64plMCH8mhS0WaEO3NDQnjxgG154Qo05bMxm+j SdyEOrj0NweFcMNkva4AeXNyX5r+e6DsKENbmNH3PVN/ZkqxuV2vX0toDM9w1ujw2/ze GhPLcYbmBBNkUsRdGWWZ2bjKXz4RCtDK2Si3DkhRnRle4hiziopKrRLyT2Q5rYj+x7nI xHEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=e+MJEyxmfK4Sv4lL3PFYCtYbhoyBCwTdEWICmQEy0YI=; b=BVha9kVAW1mIL2hKHfPQvXcTMtSpeyZzJM9FvoCBRzpz8GAC//5a98UvIIkcS3uRUE hgeLkGNPI8eH6himblJaHMVdFb7g+8nSbw2EYI93548y9dnu4s4LnOijz8Cs4Wo8GSD9 Q3Pu3sAkvgzTZIpDHUfn9xXuLjqVbFLDiC1YTO1Pbk6mU8ftDxzVqYZidmnbL3IId98h fJkZeT4bJkEtzxw5jdnsSS0MLzcT2tdwnh6nqp4zIXHNN/cJREYLhLX/eisFtHysQ88I /b2OkSOzuXgFS39G95F+fdrq1pSq4oDXQcJu5aoTAgV4bCHwot7vaXnFvG7fYEJVklXe Uc7w== X-Gm-Message-State: AGRZ1gKmuVlsT+nef2lwXwQN0mFksPxxT/vstE1FwHVznaNz/I6WSYwt Q8PQpHKsUTURF14XiZH0I0w+gQ== X-Google-Smtp-Source: AJdET5f/M1Bk9dJcXTjcUQiSeJLKp2cZaI2RJgDP2Fr4GfIZ0My4gjAnA4R1VKXgRkKoVze/MeOSdQ== X-Received: by 2002:ad4:4312:: with SMTP id c18mr26136098qvs.59.1541517016445; Tue, 06 Nov 2018 07:10:16 -0800 (PST) Received: from alvin.alvh.no-ip.org ([190.121.29.3]) by smtp.gmail.com with ESMTPSA id n8sm2097790qtk.91.2018.11.06.07.10.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Nov 2018 07:10:15 -0800 (PST) Received: by alvin.alvh.no-ip.org (Postfix, from userid 1000) id 6BEC35BE; Tue, 6 Nov 2018 12:10:13 -0300 (-03) Date: Tue, 6 Nov 2018 12:10:13 -0300 From: Alvaro Herrera To: Amit Langote Cc: Ashutosh Bapat , PostgreSQL Hackers , Amit Langote Subject: Re: BUG #15212: Default values in partition tables don't work as expected and allow NOT NULL violation Message-ID: <20181106151013.45x75xvh6jpxsqpu@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: NeoMutt/20180716 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Looking over the stuff in gram.y (to make sure there's nothing that could be lost), I noticed that we're losing the COLLATE clause when they are added to columns in partitions. I would expect part1 to end up with collation es_CL, or alternatively that the command throws an error: 55462 10.6 138851=# create table part (a text collate "en_US") partition by range (a); CREATE TABLE Duración: 23,511 ms 55462 10.6 138851=# create table part1 partition of part (a collate "es_CL") for values from ('ca') to ('cu'); CREATE TABLE Duración: 111,551 ms 55462 10.6 138851=# \d part Tabla «public.part» Columna │ Tipo │ Collation │ Nullable │ Default ─────────┼──────┼───────────┼──────────┼───────── a │ text │ en_US │ │ Partition key: RANGE (a) Number of partitions: 1 (Use \d+ to list them.) 55462 10.6 138851=# \d part1 Tabla «public.part1» Columna │ Tipo │ Collation │ Nullable │ Default ─────────┼──────┼───────────┼──────────┼───────── a │ text │ en_US │ │ Partition of: part FOR VALUES FROM ('ca') TO ('cu') (This case is particularly bothersome because the column is the partition key, so the partition range bounds would differ depending on which collation is used to compare. I assume we'd always want to use the parent table's collation; so there's even a stronger case for raising an error if it doesn't match the parent's. However, this case could arise for other columns too, where it's not *so* bad, but still not completely correct I think.) This happens on unpatched code, and doesn't seem covered by any tests. However, this seems an independent bug that isn't affected by this patch. The only other things there are deferrability markers, which seem to be propagated in a relatively sane fashion (but no luck if you want to add foreign keys with mismatching deferrability than the parent's -- you just get a dupe, and there's no way in the grammar to change the flags for the existing constraint). But you can add a UNIQUE DEFERRED constraint in a partition that wasn't there in the parent, for example. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services