From 392abca09192218a73066fd41131819963daf1a4 Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 12 Dec 2017 10:33:11 +0900 Subject: [PATCH v4] Allow Boolean values in partition FOR VALUES clause --- doc/src/sgml/ref/create_table.sgml | 14 +++++++------- src/backend/parser/gram.y | 2 ++ src/test/regress/expected/create_table.out | 14 ++++++++++++++ src/test/regress/sql/create_table.sql | 7 +++++++ 4 files changed, 30 insertions(+), 7 deletions(-) diff --git a/doc/src/sgml/ref/create_table.sgml b/doc/src/sgml/ref/create_table.sgml index a0c9a6d257..61371195ac 100644 --- a/doc/src/sgml/ref/create_table.sgml +++ b/doc/src/sgml/ref/create_table.sgml @@ -86,9 +86,9 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UNLOGGED ] TABLE [ IF NOT EXI and partition_bound_spec is: -IN ( { numeric_literal | string_literal | NULL } [, ...] ) | -FROM ( { numeric_literal | string_literal | MINVALUE | MAXVALUE } [, ...] ) - TO ( { numeric_literal | string_literal | MINVALUE | MAXVALUE } [, ...] ) | +IN ( { literal_constant } [, ...] ) | +FROM ( { literal_constant | MINVALUE | MAXVALUE } [, ...] ) + TO ( { literal_constant | MINVALUE | MAXVALUE } [, ...] ) | WITH ( MODULUS numeric_literal, REMAINDER numeric_literal ) index_parameters in UNIQUE, PRIMARY KEY, and EXCLUDE constraints are: @@ -274,10 +274,10 @@ WITH ( MODULUS numeric_literal, REM Each of the values specified in the partition_bound_spec is - a literal, NULL, MINVALUE, or - MAXVALUE. Each literal value must be either a - numeric constant that is coercible to the corresponding partition key - column's type, or a string literal that is valid input for that type. + a literal constant, MINVALUE, or + MAXVALUE. Each literal constant value must be either + a number, a Boolean, a null value, or a string that is valid input for + the partition key's type. diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y index 5329432f25..0c3bc67620 100644 --- a/src/backend/parser/gram.y +++ b/src/backend/parser/gram.y @@ -2793,6 +2793,8 @@ partbound_datum: Sconst { $$ = makeStringConst($1, @1); } | NumericOnly { $$ = makeAConst($1, @1); } | NULL_P { $$ = makeNullAConst(@1); } + | TRUE_P { $$ = makeStringConst("true", @1); } + | FALSE_P { $$ = makeStringConst("false", @1); } ; partbound_datum_list: diff --git a/src/test/regress/expected/create_table.out b/src/test/regress/expected/create_table.out index ef0906776e..ec8525f471 100644 --- a/src/test/regress/expected/create_table.out +++ b/src/test/regress/expected/create_table.out @@ -868,3 +868,17 @@ Partition key: LIST (a) Number of partitions: 0 DROP TABLE parted_col_comment; +-- boolean partitions +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 10e5d49e8e..1e5768d178 100644 --- a/src/test/regress/sql/create_table.sql +++ b/src/test/regress/sql/create_table.sql @@ -711,3 +711,10 @@ COMMENT ON COLUMN parted_col_comment.a IS 'Partition key'; SELECT obj_description('parted_col_comment'::regclass); \d+ parted_col_comment DROP TABLE parted_col_comment; + +-- boolean partitions +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; -- 2.11.0