Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jKOEZ-0004Bu-Ff for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Apr 2020 15:27:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jKOEY-0002FK-BG for pgsql-bugs@arkaria.postgresql.org; Fri, 03 Apr 2020 15:27:50 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jKOEY-0002FD-2e for pgsql-bugs@lists.postgresql.org; Fri, 03 Apr 2020 15:27:50 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from <9erthalion6@gmail.com>) id 1jKOEV-0000Q5-Fc for pgsql-bugs@lists.postgresql.org; Fri, 03 Apr 2020 15:27:49 +0000 Received: by mail-wm1-x32d.google.com with SMTP id t128so7581152wma.0 for ; Fri, 03 Apr 2020 08:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=R47of4EO8WQ1SMekfL+EzqNQLOjK0Lex6m88FmTxZrE=; b=cbabmbZrK7HLC+SwQ9vlTBgP7qYbl8+i7ra+EBQCkffndyr4nUUzi/LdSbvtShzOWH pDzVgKlM9C7taKLKqwyfXq9X/H671ybbfrU1Ltl5KTlUy1a/Nu67XWDCLgkolxmmfXNq 5FnjIG5qA8QTqb3Bhmij/6J6w8+XDZfFEPVWBfj3M7PtVaHt4mgP4rDRggq0r25MEJ/m UdJXemqXvKF9vJ5uqAbLNf/QZIL5IoDersx0P+XM7+MV6dLnuxaDBurg+hzJiudMSE2n nOY/LJyAr8yC0W1WJ04FBhIgMZ82mwsXnJ3B+s9AIg2hDDOcWkCsv1z7r1nHZ4f128PX nP0w== 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:references :mime-version:content-disposition:in-reply-to; bh=R47of4EO8WQ1SMekfL+EzqNQLOjK0Lex6m88FmTxZrE=; b=SFN4ue1Ob2h+yFR7qlSCbqN8yHaewzWV9CkegVatXvxwqW3BKCd8wNy6pWRqV9OQ6O Rlq0rAaDqVn1dJz727Msw5YoaTRA3g1uWk5gS/5Rjms3u4MJ9J6RPndG/eh1jg8gtK8y w6zqmXOtgIgXYfV8T8sfzU/TMWhIhLYDJgun6nQwmCgGQBvrav7zAPs98oUNKx27HjpW Wb7kayNkepQ0fRWPr8XvHlayD+LgROELHcdlyD9cQSaC6m/eoHHHdsf/pGzrnrwsvkKb P0ZmhmPjZck0DIKAWIM4K8VaFnbPAKh6sNQU6BLuqfBm8Fibb2FF2nJKlDr0pyjl9tPg 3maA== X-Gm-Message-State: AGi0Pub0Xme+Ib6SVhw8u83MV47yKLgRZhnM2f7tcxojyEWldX7jE45r 6xNTigcfZhp9P77sFVyfMnU= X-Google-Smtp-Source: APiQypKhZ6pVu5J9waGzZNAtj9SziVdnpDK688p2yAPYmg64tgpIRQmqbqPCnFNNGjytwPA7M376vg== X-Received: by 2002:a1c:41d6:: with SMTP id o205mr9117626wma.122.1585927666647; Fri, 03 Apr 2020 08:27:46 -0700 (PDT) Received: from localhost (dslb-094-222-004-201.094.222.pools.vodafone-ip.de. [94.222.4.201]) by smtp.gmail.com with ESMTPSA id p17sm11571486wmb.30.2020.04.03.08.27.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Apr 2020 08:27:45 -0700 (PDT) Date: Fri, 3 Apr 2020 17:29:10 +0200 From: Dmitry Dolgov <9erthalion6@gmail.com> To: Michael Paquier Cc: exclusion@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #16325: Assert failure on partitioning by int for a text value with a collation Message-ID: <20200403152910.rsdc2yg7bisqaltb@localhost> References: <16325-809194cf742313ab@postgresql.org> <20200328125303.4me6vetvzgebobw5@localhost> <20200401070842.GD142683@paquier.xyz> <20200401120117.qkmjxi3xrumbnd3s@localhost> <20200402020150.GA2803@paquier.xyz> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="vbkt76vvjbwxtx4r" Content-Disposition: inline In-Reply-To: <20200402020150.GA2803@paquier.xyz> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --vbkt76vvjbwxtx4r Content-Type: text/plain; charset=us-ascii Content-Disposition: inline > On Thu, Apr 02, 2020 at 11:01:50AM +0900, Michael Paquier wrote: > > > + /* > > + * No need to check if exprCollOid is invalid, since if it would be, > > + * then transformCollateClause will throw an error earlier > > + */ > > + if (!type_is_collatable(colType)) > > + ereport(ERROR, > > + (errcode(ERRCODE_DATATYPE_MISMATCH), > > + errmsg("collations are not supported by type %s", > > + format_type_be(colType)))); > > + > > > > if (OidIsValid(exprCollOid) && > > exprCollOid != DEFAULT_COLLATION_OID && > > exprCollOid != partCollation) > > Another point that could be made is that as we know that we are in the > presence of a CollateExpr() here, and exprCollOid will never be > InvalidOid. So there could be a point in using an assertion instead > of the check done below making sure that exprCollOid is always valid? Thanks for the suggestion. It's not strictly related to the fix I guess, but of course you're right, and we can indeed improve this part and replace the check with an assert. --vbkt76vvjbwxtx4r Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="part_value_collations_v3.patch" diff --git a/src/backend/parser/parse_utilcmd.c b/src/backend/parser/parse_utilcmd.c index c1911411d0..1468fd2460 100644 --- a/src/backend/parser/parse_utilcmd.c +++ b/src/backend/parser/parse_utilcmd.c @@ -4069,8 +4069,18 @@ transformPartitionBoundValue(ParseState *pstate, Node *val, { Oid exprCollOid = exprCollation(value); - if (OidIsValid(exprCollOid) && - exprCollOid != DEFAULT_COLLATION_OID && + /* + * No need to check if exprCollOid is invalid, since if it would be, + * then transformCollateClause will throw an error earlier + */ + if (!type_is_collatable(colType)) + ereport(ERROR, + (errcode(ERRCODE_DATATYPE_MISMATCH), + errmsg("collations are not supported by type %s", + format_type_be(colType)))); + + Assert(OidIsValid(exprCollOid)); + if (exprCollOid != DEFAULT_COLLATION_OID && exprCollOid != partCollation) ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index c5e95edbed..abd1bfe2b9 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -594,6 +594,8 @@ CREATE TABLE list_parted ( CREATE TABLE part_p1 PARTITION OF list_parted FOR VALUES IN ('1'); CREATE TABLE part_p2 PARTITION OF list_parted FOR VALUES IN (2); CREATE TABLE part_p3 PARTITION OF list_parted FOR VALUES IN ((2+1)); +CREATE TABLE part_p4 PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX"); +ERROR: collations are not supported by type integer CREATE TABLE part_null PARTITION OF list_parted FOR VALUES IN (null); \d+ list_parted Partitioned table "public.list_parted" diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql index 00ef81a685..3fe77a7711 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -522,6 +522,7 @@ CREATE TABLE list_parted ( CREATE TABLE part_p1 PARTITION OF list_parted FOR VALUES IN ('1'); CREATE TABLE part_p2 PARTITION OF list_parted FOR VALUES IN (2); CREATE TABLE part_p3 PARTITION OF list_parted FOR VALUES IN ((2+1)); +CREATE TABLE part_p4 PARTITION OF list_parted FOR VALUES IN ('1' collate "POSIX"); CREATE TABLE part_null PARTITION OF list_parted FOR VALUES IN (null); \d+ list_parted --vbkt76vvjbwxtx4r--