Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1e5e4ef

Browse files
committed
Error position support for partition specifications
Add support for error position reporting for partition specifications. Reviewed-by: Fabien COELHO <[email protected]>
1 parent a4a232b commit 1e5e4ef

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

src/backend/commands/tablecmds.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ static void RangeVarCallbackForDropRelation(const RangeVar *rel, Oid relOid,
478478
static void RangeVarCallbackForAlterRelation(const RangeVar *rv, Oid relid,
479479
Oid oldrelid, void *arg);
480480
static PartitionSpec *transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy);
481-
static void ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
481+
static void ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs,
482482
List **partexprs, Oid *partopclass, Oid *partcollation, char strategy);
483483
static void CreateInheritance(Relation child_rel, Relation parent_rel);
484484
static void RemoveInheritance(Relation child_rel, Relation parent_rel);
@@ -875,13 +875,17 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
875875
*/
876876
if (stmt->partspec)
877877
{
878+
ParseState *pstate;
878879
char strategy;
879880
int partnatts;
880881
AttrNumber partattrs[PARTITION_MAX_KEYS];
881882
Oid partopclass[PARTITION_MAX_KEYS];
882883
Oid partcollation[PARTITION_MAX_KEYS];
883884
List *partexprs = NIL;
884885

886+
pstate = make_parsestate(NULL);
887+
pstate->p_sourcetext = queryString;
888+
885889
partnatts = list_length(stmt->partspec->partParams);
886890

887891
/* Protect fixed-size arrays here and in executor */
@@ -900,7 +904,7 @@ DefineRelation(CreateStmt *stmt, char relkind, Oid ownerId,
900904
stmt->partspec = transformPartitionSpec(rel, stmt->partspec,
901905
&strategy);
902906

903-
ComputePartitionAttrs(rel, stmt->partspec->partParams,
907+
ComputePartitionAttrs(pstate, rel, stmt->partspec->partParams,
904908
partattrs, &partexprs, partopclass,
905909
partcollation, strategy);
906910

@@ -13695,7 +13699,7 @@ transformPartitionSpec(Relation rel, PartitionSpec *partspec, char *strategy)
1369513699
* Expressions in the PartitionElems must be parse-analyzed already.
1369613700
*/
1369713701
static void
13698-
ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
13702+
ComputePartitionAttrs(ParseState *pstate, Relation rel, List *partParams, AttrNumber *partattrs,
1369913703
List **partexprs, Oid *partopclass, Oid *partcollation,
1370013704
char strategy)
1370113705
{
@@ -13722,14 +13726,16 @@ ComputePartitionAttrs(Relation rel, List *partParams, AttrNumber *partattrs,
1372213726
ereport(ERROR,
1372313727
(errcode(ERRCODE_UNDEFINED_COLUMN),
1372413728
errmsg("column \"%s\" named in partition key does not exist",
13725-
pelem->name)));
13729+
pelem->name),
13730+
parser_errposition(pstate, pelem->location)));
1372613731
attform = (Form_pg_attribute) GETSTRUCT(atttuple);
1372713732

1372813733
if (attform->attnum <= 0)
1372913734
ereport(ERROR,
1373013735
(errcode(ERRCODE_INVALID_OBJECT_DEFINITION),
1373113736
errmsg("cannot use system column \"%s\" in partition key",
13732-
pelem->name)));
13737+
pelem->name),
13738+
parser_errposition(pstate, pelem->location)));
1373313739

1373413740
partattrs[attn] = attform->attnum;
1373513741
atttype = attform->atttypid;

src/test/regress/expected/create_table.out

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,15 @@ CREATE TABLE partitioned (
328328
a int
329329
) PARTITION BY RANGE (b);
330330
ERROR: column "b" named in partition key does not exist
331+
LINE 3: ) PARTITION BY RANGE (b);
332+
^
331333
-- cannot use system columns in partition key
332334
CREATE TABLE partitioned (
333335
a int
334336
) PARTITION BY RANGE (xmin);
335337
ERROR: cannot use system column "xmin" in partition key
338+
LINE 3: ) PARTITION BY RANGE (xmin);
339+
^
336340
-- functions in key must be immutable
337341
CREATE FUNCTION immut_func (a int) RETURNS int AS $$ SELECT a + random()::int; $$ LANGUAGE SQL;
338342
CREATE TABLE partitioned (
@@ -719,6 +723,8 @@ SELECT conislocal, coninhcount FROM pg_constraint WHERE conrelid = 'part_b'::reg
719723
-- specify PARTITION BY for a partition
720724
CREATE TABLE fail_part_col_not_found PARTITION OF parted FOR VALUES IN ('c') PARTITION BY RANGE (c);
721725
ERROR: column "c" named in partition key does not exist
726+
LINE 1: ...TITION OF parted FOR VALUES IN ('c') PARTITION BY RANGE (c);
727+
^
722728
CREATE TABLE part_c PARTITION OF parted (b WITH OPTIONS NOT NULL DEFAULT 0) FOR VALUES IN ('c') PARTITION BY RANGE ((b));
723729
-- create a level-2 partition
724730
CREATE TABLE part_c_1_10 PARTITION OF part_c FOR VALUES FROM (1) TO (10);

0 commit comments

Comments
 (0)