Skip to content

Commit 3439f84

Browse files
committed
Disallow finite partition bound following earlier UNBOUNDED column.
Amit Langote, per an observation by me. Discussion: http://postgr.es/m/CA+TgmoYWnV2GMnYLG-Czsix-E1WGAbo4D+0tx7t9NdfYBDMFsA@mail.gmail.com
1 parent 489b96e commit 3439f84

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

src/backend/parser/parse_utilcmd.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3358,6 +3358,7 @@ transformPartitionBound(ParseState *pstate, Relation parent, Node *bound)
33583358
int i,
33593359
j;
33603360
char *colname;
3361+
bool seen_unbounded;
33613362

33623363
if (spec->strategy != PARTITION_STRATEGY_RANGE)
33633364
ereport(ERROR,
@@ -3376,6 +3377,39 @@ transformPartitionBound(ParseState *pstate, Relation parent, Node *bound)
33763377
(errcode(ERRCODE_INVALID_TABLE_DEFINITION),
33773378
errmsg("TO must specify exactly one value per partitioning column")));
33783379

3380+
/*
3381+
* Check that no finite value follows a UNBOUNDED literal in either of
3382+
* lower and upper bound lists.
3383+
*/
3384+
seen_unbounded = false;
3385+
foreach(cell1, spec->lowerdatums)
3386+
{
3387+
PartitionRangeDatum *ldatum;
3388+
3389+
ldatum = (PartitionRangeDatum *) lfirst(cell1);
3390+
if (ldatum->infinite)
3391+
seen_unbounded = true;
3392+
else if (seen_unbounded)
3393+
ereport(ERROR,
3394+
(errcode(ERRCODE_DATATYPE_MISMATCH),
3395+
errmsg("cannot specify finite value after UNBOUNDED"),
3396+
parser_errposition(pstate, exprLocation((Node *) ldatum))));
3397+
}
3398+
seen_unbounded = false;
3399+
foreach(cell1, spec->upperdatums)
3400+
{
3401+
PartitionRangeDatum *rdatum;
3402+
3403+
rdatum = (PartitionRangeDatum *) lfirst(cell1);
3404+
if (rdatum->infinite)
3405+
seen_unbounded = true;
3406+
else if (seen_unbounded)
3407+
ereport(ERROR,
3408+
(errcode(ERRCODE_DATATYPE_MISMATCH),
3409+
errmsg("cannot specify finite value after UNBOUNDED"),
3410+
parser_errposition(pstate, exprLocation((Node *) rdatum))));
3411+
}
3412+
33793413
i = j = 0;
33803414
result_spec->lowerdatums = result_spec->upperdatums = NIL;
33813415
forboth(cell1, spec->lowerdatums, cell2, spec->upperdatums)

src/test/regress/expected/create_table.out

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,13 @@ ERROR: TO must specify exactly one value per partitioning column
505505
-- cannot specify null values in range bounds
506506
CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES FROM (null) TO (unbounded);
507507
ERROR: cannot specify NULL in range bound
508+
-- cannot specify finite values after UNBOUNDED has been specified
509+
CREATE TABLE range_parted_multicol (a int, b int, c int) PARTITION BY RANGE (a, b, c);
510+
CREATE TABLE fail_part PARTITION OF range_parted_multicol FOR VALUES FROM (1, UNBOUNDED, 1) TO (UNBOUNDED, 1, 1);
511+
ERROR: cannot specify finite value after UNBOUNDED
512+
LINE 1: ...ge_parted_multicol FOR VALUES FROM (1, UNBOUNDED, 1) TO (UNB...
513+
^
514+
DROP TABLE range_parted_multicol;
508515
-- check if compatible with the specified parent
509516
-- cannot create as partition of a non-partitioned table
510517
CREATE TABLE unparted (

src/test/regress/sql/create_table.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,11 @@ CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES FROM ('a') TO ('z',
473473
-- cannot specify null values in range bounds
474474
CREATE TABLE fail_part PARTITION OF range_parted FOR VALUES FROM (null) TO (unbounded);
475475

476+
-- cannot specify finite values after UNBOUNDED has been specified
477+
CREATE TABLE range_parted_multicol (a int, b int, c int) PARTITION BY RANGE (a, b, c);
478+
CREATE TABLE fail_part PARTITION OF range_parted_multicol FOR VALUES FROM (1, UNBOUNDED, 1) TO (UNBOUNDED, 1, 1);
479+
DROP TABLE range_parted_multicol;
480+
476481
-- check if compatible with the specified parent
477482

478483
-- cannot create as partition of a non-partitioned table

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy