aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2018-04-23 15:29:11 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2018-04-23 15:29:11 -0400
commit4df58f7ed7f9ddc5a3196fcbad35690d1b3218de (patch)
treeb29e08a24c1bb4066cb4e509b076103cf0206fb7 /src
parentdf044026fcaf60b22291c31f4290a3b09ecf5833 (diff)
downloadpostgresql-4df58f7ed7f9ddc5a3196fcbad35690d1b3218de.tar.gz
postgresql-4df58f7ed7f9ddc5a3196fcbad35690d1b3218de.zip
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
Diffstat (limited to 'src')
-rw-r--r--src/backend/parser/gram.y2
-rw-r--r--src/test/regress/expected/create_table.out14
-rw-r--r--src/test/regress/sql/create_table.sql7
3 files changed, 23 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index e5484766234..5a363674464 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -2798,6 +2798,8 @@ hash_partbound:
partbound_datum:
Sconst { $$ = makeStringConst($1, @1); }
| NumericOnly { $$ = makeAConst($1, @1); }
+ | TRUE_P { $$ = makeStringConst(pstrdup("true"), @1); }
+ | FALSE_P { $$ = makeStringConst(pstrdup("false"), @1); }
| NULL_P { $$ = makeNullAConst(@1); }
;
diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out
index 654464c6316..470fca0cab7 100644
--- a/src/test/regress/expected/create_table.out
+++ b/src/test/regress/expected/create_table.out
@@ -885,3 +885,17 @@ Partition of: arrlp FOR VALUES IN ('{1}', '{2}')
Partition constraint: ((a IS NOT NULL) AND (((a)::anyarray OPERATOR(pg_catalog.=) '{1}'::integer[]) OR ((a)::anyarray OPERATOR(pg_catalog.=) '{2}'::integer[])))
DROP TABLE arrlp;
+-- partition on boolean column
+create table boolspart (a bool) partition by list (a);
+create table boolspart_t partition of boolspart for values in (true);
+create table boolspart_f partition of boolspart for values in (false);
+\d+ boolspart
+ Table "public.boolspart"
+ Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
+--------+---------+-----------+----------+---------+---------+--------------+-------------
+ a | boolean | | | | plain | |
+Partition key: LIST (a)
+Partitions: boolspart_f FOR VALUES IN (false),
+ boolspart_t FOR VALUES IN (true)
+
+drop table boolspart;
diff --git a/src/test/regress/sql/create_table.sql b/src/test/regress/sql/create_table.sql
index 54694347aed..140bf41f765 100644
--- a/src/test/regress/sql/create_table.sql
+++ b/src/test/regress/sql/create_table.sql
@@ -719,3 +719,10 @@ CREATE TABLE arrlp (a int[]) PARTITION BY LIST (a);
CREATE TABLE arrlp12 PARTITION OF arrlp FOR VALUES IN ('{1}', '{2}');
\d+ arrlp12
DROP TABLE arrlp;
+
+-- partition on boolean column
+create table boolspart (a bool) partition by list (a);
+create table boolspart_t partition of boolspart for values in (true);
+create table boolspart_f partition of boolspart for values in (false);
+\d+ boolspart
+drop table boolspart;