Skip to content

Commit 2131d45

Browse files
committed
Remove undocumented restriction against duplicate partition key columns.
transformPartitionSpec rejected duplicate simple partition columns (e.g., "PARTITION BY RANGE (x,x)") but paid no attention to expression columns, resulting in inconsistent behavior. Worse, cases like "PARTITION BY RANGE (x,(x))") were accepted but would then result in dump/reload failures, since the expression (x) would get simplified to a plain column later. There seems no better reason for this restriction than there was for the one against duplicate included index columns (cf commit 701fd0b), so let's just remove it. Back-patch to v10 where this code was added. Report and patch by Yugo Nagata. Discussion: https://postgr.es/m/20180712165939.36b12aff.nagata@sraoss.co.jp
1 parent 0d26812 commit 2131d45

File tree

3 files changed

+0
-25
lines changed

3 files changed

+0
-25
lines changed

src/backend/commands/tablecmds.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13223,21 +13223,6 @@ transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy)
1322313223
foreach(l, partspec->partParams)
1322413224
{
1322513225
PartitionElem *pelem = castNode(PartitionElem, lfirst(l));
13226-
ListCell *lc;
13227-
13228-
/* Check for PARTITION BY ... (foo, foo) */
13229-
foreach(lc, newspec->partParams)
13230-
{
13231-
PartitionElem *pparam = castNode(PartitionElem, lfirst(lc));
13232-
13233-
if (pelem->name && pparam->name &&
13234-
strcmp(pelem->name, pparam->name) == 0)
13235-
ereport(ERROR,
13236-
(errcode(ERRCODE_DUPLICATE_COLUMN),
13237-
errmsg("column \"%s\" appears more than once in partition key",
13238-
pelem->name),
13239-
parser_errposition(pstate, pelem->location)));
13240-
}
1324113226

1324213227
if (pelem->expr)
1324313228
{

src/test/regress/expected/create_table.out

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,11 +305,6 @@ CREATE TABLE partitioned (
305305
ERROR: exclusion constraints are not supported on partitioned tables
306306
LINE 3: EXCLUDE USING gist (a WITH &&)
307307
^
308-
-- prevent column from being used twice in the partition key
309-
CREATE TABLE partitioned (
310-
a int
311-
) PARTITION BY RANGE (a, a);
312-
ERROR: column "a" appears more than once in partition key
313308
-- prevent using prohibited expressions in the key
314309
CREATE FUNCTION retset (a int) RETURNS SETOF int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
315310
CREATE TABLE partitioned (

src/test/regress/sql/create_table.sql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -315,11 +315,6 @@ CREATE TABLE partitioned (
315315
EXCLUDE USING gist (a WITH &&)
316316
) PARTITION BY RANGE (a);
317317

318-
-- prevent column from being used twice in the partition key
319-
CREATE TABLE partitioned (
320-
a int
321-
) PARTITION BY RANGE (a, a);
322-
323318
-- prevent using prohibited expressions in the key
324319
CREATE FUNCTION retset (a int) RETURNS SETOF int AS $$ SELECT 1; $$ LANGUAGE SQL IMMUTABLE;
325320
CREATE TABLE partitioned (

0 commit comments

Comments
 (0)