Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 1222db9

Browse files
committed
Fix handling of partition bounds for boolean partitioning columns.
Previously, you could partition by a boolean column as long as you spelled the bound values as string literals, for instance FOR VALUES IN ('t'). The trouble with this is that ruleutils.c printed that as FOR VALUES IN (TRUE), which is reasonable syntax but wasn't accepted by the grammar. That results in dump-and-reload failures for such cases. Apply a minimal fix that just causes TRUE and FALSE to be converted to strings 'true' and 'false'. This is pretty grotty, but it's too late for a more principled fix in v11 (to say nothing of v10). We should revisit the whole issue of how partition bound values are parsed for v12. Amit Langote Discussion: https://postgr.es/m/e05c5162-1103-7e37-d1ab-6de3e0afaf70@lab.ntt.co.jp
1 parent fab4eca commit 1222db9

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI
8686

8787
<phrase>and <replaceable class="PARAMETER">partition_bound_spec</replaceable> is:</phrase>
8888

89-
IN ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | NULL } [, ...] ) |
90-
FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | MINVALUE | MAXVALUE } [, ...] )
91-
TO ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | MINVALUE | MAXVALUE } [, ...] )
89+
IN ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | TRUE | FALSE | NULL } [, ...] ) |
90+
FROM ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | TRUE | FALSE | MINVALUE | MAXVALUE } [, ...] )
91+
TO ( { <replaceable class="PARAMETER">numeric_literal</replaceable> | <replaceable class="PARAMETER">string_literal</replaceable> | TRUE | FALSE | MINVALUE | MAXVALUE } [, ...] )
9292

9393
<phrase><replaceable class="PARAMETER">index_parameters</replaceable> in <literal>UNIQUE</literal>, <literal>PRIMARY KEY</literal>, and <literal>EXCLUDE</literal> constraints are:</phrase>
9494

src/backend/parser/gram.y

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2649,6 +2649,8 @@ ForValues:
26492649
partbound_datum:
26502650
Sconst { $$ = makeStringConst($1, @1); }
26512651
| NumericOnly { $$ = makeAConst($1, @1); }
2652+
| TRUE_P { $$ = makeStringConst(pstrdup("true"), @1); }
2653+
| FALSE_P { $$ = makeStringConst(pstrdup("false"), @1); }
26522654
| NULL_P { $$ = makeNullAConst(@1); }
26532655
;
26542656

src/test/regress/expected/create_table.out

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -811,3 +811,17 @@ Partition of: arrlp FOR VALUES IN ('{1}', '{2}')
811811
Partition constraint: ((a IS NOT NULL) AND (((a)::anyarray OPERATOR(pg_catalog.=) '{1}'::integer[]) OR ((a)::anyarray OPERATOR(pg_catalog.=) '{2}'::integer[])))
812812

813813
DROP TABLE arrlp;
814+
-- partition on boolean column
815+
create table boolspart (a bool) partition by list (a);
816+
create table boolspart_t partition of boolspart for values in (true);
817+
create table boolspart_f partition of boolspart for values in (false);
818+
\d+ boolspart
819+
Table "public.boolspart"
820+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
821+
--------+---------+-----------+----------+---------+---------+--------------+-------------
822+
a | boolean | | | | plain | |
823+
Partition key: LIST (a)
824+
Partitions: boolspart_f FOR VALUES IN (false),
825+
boolspart_t FOR VALUES IN (true)
826+
827+
drop table boolspart;

src/test/regress/sql/create_table.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,3 +668,10 @@ CREATE TABLE arrlp (a int[]) PARTITION BY LIST (a);
668668
CREATE TABLE arrlp12 PARTITION OF arrlp FOR VALUES IN ('{1}', '{2}');
669669
\d+ arrlp12
670670
DROP TABLE arrlp;
671+
672+
-- partition on boolean column
673+
create table boolspart (a bool) partition by list (a);
674+
create table boolspart_t partition of boolspart for values in (true);
675+
create table boolspart_f partition of boolspart for values in (false);
676+
\d+ boolspart
677+
drop table boolspart;

0 commit comments

Comments
 (0)