diff --git a/src/backend/cdb/cdbpartition.c b/src/backend/cdb/cdbpartition.c index e2200df7354f48fbbde318028504b58242066d01..b4fabe661e97a80f37d053fcbcd1753f737bb6ef 100644 --- a/src/backend/cdb/cdbpartition.c +++ b/src/backend/cdb/cdbpartition.c @@ -3658,7 +3658,7 @@ magic_expr_to_datum(Relation rel, PartitionNode *partnode, /* see coerce_partition_value */ Node *out; - out = coerce_partition_value(n1, lhsid, attribute->atttypmod, + out = coerce_partition_value(NULL, n1, lhsid, attribute->atttypmod, char_to_parttype(partnode->part->parkind)); if (!out) ereport(ERROR, diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c index ea537f3e916d4b52ada84da3dbf90ff7e2313c64..152561730835abf7276377e5e72539a8ede65cff 100644 --- a/src/backend/commands/tablecmds.c +++ b/src/backend/commands/tablecmds.c @@ -4713,7 +4713,7 @@ ATPrepCmd(List **wqueue, Relation rel, AlterTableCmd *cmd, PartitionByType t = (parkind == 'r') ? PARTTYP_RANGE : PARTTYP_LIST; - n = coerce_partition_value(n, typid, typmod, t); + n = coerce_partition_value(NULL, n, typid, typmod, t); lfirst(lc2) = n; diff --git a/src/backend/parser/parse_partition.c b/src/backend/parser/parse_partition.c index d1bebccd24ab7fe0dcba39a37a811c3755aafdba..9dfb21f4a9982b143b7b69f5c75e35bad8ae0d43 100644 --- a/src/backend/parser/parse_partition.c +++ b/src/backend/parser/parse_partition.c @@ -2714,14 +2714,16 @@ preprocess_range_spec(partValidationState *vstate) typenameTypeIdAndMod(pstate, typ, &typid, &typmod); - newnode = coerce_partition_value(lfirst(lcstart), + newnode = coerce_partition_value(pstate, + lfirst(lcstart), typid, typmod, PARTTYP_RANGE); lfirst(lcstart) = newnode; /* be sure we coerce the end value */ - newnode = coerce_partition_value(lfirst(lcend), + newnode = coerce_partition_value(pstate, + lfirst(lcend), typid, typmod, PARTTYP_RANGE); @@ -2767,7 +2769,8 @@ preprocess_range_spec(partValidationState *vstate) ReleaseSysCache(newetyp); /* we need to coerce */ - e = coerce_partition_value(e, + e = coerce_partition_value(pstate, + e, newrtypeId, typmod, PARTTYP_RANGE); @@ -3001,7 +3004,8 @@ preprocess_range_spec(partValidationState *vstate) typenameTypeIdAndMod(pstate, typ, &typid, &typmod); - newnode = coerce_partition_value(mystart, + newnode = coerce_partition_value(pstate, + mystart, typid, typmod, PARTTYP_RANGE); @@ -3028,7 +3032,8 @@ preprocess_range_spec(partValidationState *vstate) typenameTypeIdAndMod(pstate, typ, &typid, &typmod); - newnode = coerce_partition_value(myend, + newnode = coerce_partition_value(pstate, + myend, typid, typmod, PARTTYP_RANGE); @@ -4361,7 +4366,8 @@ validate_list_partition(partValidationState *vstate) Oid typid; typenameTypeIdAndMod(pstate, type, &typid, &typmod); - node = coerce_partition_value(node, typid, typmod, + node = coerce_partition_value(pstate, + node, typid, typmod, PARTTYP_LIST); tvals = lappend(tvals, node); @@ -4639,7 +4645,7 @@ range_partition_walker(Node *node, void *context) } Node * -coerce_partition_value(Node *node, Oid typid, int32 typmod, +coerce_partition_value(ParseState *pstate, Node *node, Oid typid, int32 typmod, PartitionByType partype) { Oid typcollation; @@ -4654,30 +4660,11 @@ coerce_partition_value(Node *node, Oid typid, int32 typmod, /* MPP-3626: better error message */ if (!out) - { - char *pparam; - StringInfoData sid; - - initStringInfo(&sid); - - /* - * Try to build a printable string of the node value. - * deparse_expression() returns a palloc'd buffer from a StringInfo so - * we can safely inspect it. - */ - pparam = deparse_expression(node, - deparse_context_for("partition", InvalidOid), - false, false); - if (strlen(pparam) != 0) - appendStringInfo(&sid, "(%s) ", pparam); - ereport(ERROR, (errcode(ERRCODE_DATATYPE_MISMATCH), - errmsg("cannot coerce %s partition parameter %sto column type (%s)", - (partype == PARTTYP_LIST) ? "LIST" : "RANGE", - sid.data, - format_type_be(typid)))); - } + errmsg("cannot coerce partition parameter to column type \"%s\"", + format_type_be(typid)), + parser_errposition(pstate, exprLocation(node)))); /* * GPDB_91_MERGE_FIXME: For now, partition specifications always use diff --git a/src/include/parser/parse_partition.h b/src/include/parser/parse_partition.h index b0cd3fa2862f32ab1f794ef230c595f5741067c9..8d20141ba46b9548fa7919ce3c46039dee7d846d 100644 --- a/src/include/parser/parse_partition.h +++ b/src/include/parser/parse_partition.h @@ -19,7 +19,7 @@ extern void transformPartitionBy(CreateStmtContext *cxt, CreateStmt *stmt, Node *partitionBy); extern void PartitionRangeItemIsValid(ParseState *pstate, PartitionRangeItem *pri); -extern Node *coerce_partition_value(Node *node, Oid typid, int32 typmod, +extern Node *coerce_partition_value(ParseState *pstate, Node *node, Oid typid, int32 typmod, PartitionByType partype); #endif /* PARSE_PARTITION_H */ diff --git a/src/test/regress/expected/bfv_partition.out b/src/test/regress/expected/bfv_partition.out index 8fb06107354baf6739ecf9a37374902723311225..721ddb307cfa93aa555e227459b9552f0944b4ae 100644 --- a/src/test/regress/expected/bfv_partition.out +++ b/src/test/regress/expected/bfv_partition.out @@ -3728,7 +3728,9 @@ start (date '2005-01-01') ); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. -ERROR: cannot coerce RANGE partition parameter ('01-01-2001'::date) to column type (integer) +ERROR: cannot coerce partition parameter to column type "integer" +LINE 6: start (date '2001-01-01'), + ^ set optimizer_analyze_root_partition=on; create table mpp3487 (i int) partition by range (i) (start(1) end(10) every(1)); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'i' as the Greenplum Database data distribution key for this table. diff --git a/src/test/regress/expected/partition.out b/src/test/regress/expected/partition.out index a5faf4ab3b4f3b451bec4f756e86f2765bd22630..13e2ab6eced309bedb36f8092b59dc941f2bc253 100755 --- a/src/test/regress/expected/partition.out +++ b/src/test/regress/expected/partition.out @@ -2026,7 +2026,9 @@ create table f (n numeric(20, 2)) partition by range(n) (start(1::bigint) end('f'::bool)); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'n' as the Greenplum Database data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. -ERROR: cannot coerce RANGE partition parameter (false) to column type (numeric) +ERROR: cannot coerce partition parameter to column type "numeric" +LINE 2: end('f'::bool)); + ^ -- see that grant and revoke cascade to children create role part_role; NOTICE: resource queue required -- using default resource queue "pg_default" diff --git a/src/test/regress/expected/partition_optimizer.out b/src/test/regress/expected/partition_optimizer.out index e9b7e0ebf0b619764d79316404e60589ef076f8d..2d298a7a6915c27a43bea7e749a357d99051ad51 100755 --- a/src/test/regress/expected/partition_optimizer.out +++ b/src/test/regress/expected/partition_optimizer.out @@ -2030,7 +2030,9 @@ create table f (n numeric(20, 2)) partition by range(n) (start(1::bigint) end('f'::bool)); NOTICE: Table doesn't have 'DISTRIBUTED BY' clause -- Using column named 'n' as the Greenplum Database data distribution key for this table. HINT: The 'DISTRIBUTED BY' clause determines the distribution of data. Make sure column(s) chosen are the optimal data distribution key to minimize skew. -ERROR: cannot coerce RANGE partition parameter (false) to column type (numeric) +ERROR: cannot coerce partition parameter to column type "numeric" +LINE 2: end('f'::bool)); + ^ -- see that grant and revoke cascade to children create role part_role; NOTICE: resource queue required -- using default resource queue "pg_default"