Skip to content

Commit 4f981df

Browse files
committed
Report a more useful error for reloptions on a partitioned table.
Previously, trying to set storage parameters on a partitioned table always led to "unrecognized parameter foo", because the code expected there might be some valid parameters; but there aren't any. The docs make clear that it's intended that there never will be any, so let's replace this useless search with a more to-the-point message. Simon Riggs and Karina Litskevich Discussion: https://postgr.es/m/CANbhV-H=eZ9kTR9mUgKGK0Qv9uXP=U+dQg3rinQHfTdFMhBA2A@mail.gmail.com
1 parent e613ace commit 4f981df

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

src/backend/access/common/reloptions.c

+6-7
Original file line numberDiff line numberDiff line change
@@ -1984,13 +1984,12 @@ build_local_reloptions(local_relopts *relopts, Datum options, bool validate)
19841984
bytea *
19851985
partitioned_table_reloptions(Datum reloptions, bool validate)
19861986
{
1987-
/*
1988-
* There are no options for partitioned tables yet, but this is able to do
1989-
* some validation.
1990-
*/
1991-
return (bytea *) build_reloptions(reloptions, validate,
1992-
RELOPT_KIND_PARTITIONED,
1993-
0, NULL, 0);
1987+
if (validate && reloptions)
1988+
ereport(ERROR,
1989+
errcode(ERRCODE_WRONG_OBJECT_TYPE),
1990+
errmsg("cannot specify storage parameters for a partitioned table"),
1991+
errhint("Specify storage parameters for its leaf partitions, instead."));
1992+
return NULL;
19941993
}
19951994

19961995
/*

src/test/regress/expected/alter_table.out

+4
Original file line numberDiff line numberDiff line change
@@ -3801,6 +3801,10 @@ ALTER TABLE partitioned DROP COLUMN b;
38013801
ERROR: cannot drop column "b" because it is part of the partition key of relation "partitioned"
38023802
ALTER TABLE partitioned ALTER COLUMN b TYPE char(5);
38033803
ERROR: cannot alter column "b" because it is part of the partition key of relation "partitioned"
3804+
-- specifying storage parameters for partitioned tables is not supported
3805+
ALTER TABLE partitioned SET (fillfactor=100);
3806+
ERROR: cannot specify storage parameters for a partitioned table
3807+
HINT: Specify storage parameters for its leaf partitions, instead.
38043808
-- partitioned table cannot participate in regular inheritance
38053809
CREATE TABLE nonpartitioned (
38063810
a int,

src/test/regress/expected/create_table.out

+4
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ Partition key: LIST (a)
987987
Number of partitions: 0
988988

989989
DROP TABLE parted_col_comment;
990+
-- specifying storage parameters for partitioned tables is not supported
991+
CREATE TABLE parted_col_comment (a int, b text) PARTITION BY LIST (a) WITH (fillfactor=100);
992+
ERROR: cannot specify storage parameters for a partitioned table
993+
HINT: Specify storage parameters for its leaf partitions, instead.
990994
-- list partitioning on array type column
991995
CREATE TABLE arrlp (a int[]) PARTITION BY LIST (a);
992996
CREATE TABLE arrlp12 PARTITION OF arrlp FOR VALUES IN ('{1}', '{2}');

src/test/regress/sql/alter_table.sql

+3
Original file line numberDiff line numberDiff line change
@@ -2325,6 +2325,9 @@ ALTER TABLE partitioned ALTER COLUMN a TYPE char(5);
23252325
ALTER TABLE partitioned DROP COLUMN b;
23262326
ALTER TABLE partitioned ALTER COLUMN b TYPE char(5);
23272327

2328+
-- specifying storage parameters for partitioned tables is not supported
2329+
ALTER TABLE partitioned SET (fillfactor=100);
2330+
23282331
-- partitioned table cannot participate in regular inheritance
23292332
CREATE TABLE nonpartitioned (
23302333
a int,

src/test/regress/sql/create_table.sql

+3
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ SELECT obj_description('parted_col_comment'::regclass);
652652
\d+ parted_col_comment
653653
DROP TABLE parted_col_comment;
654654

655+
-- specifying storage parameters for partitioned tables is not supported
656+
CREATE TABLE parted_col_comment (a int, b text) PARTITION BY LIST (a) WITH (fillfactor=100);
657+
655658
-- list partitioning on array type column
656659
CREATE TABLE arrlp (a int[]) PARTITION BY LIST (a);
657660
CREATE TABLE arrlp12 PARTITION OF arrlp FOR VALUES IN ('{1}', '{2}');

0 commit comments

Comments
 (0)