提交 a0e41dc7 编写于 作者: H Heikki Linnakangas

Add error position to error on coercing partition boundaries.

I think this is more clear. Now that we the error position is displayed
with the error, we don't need to work so hard to deparse the value and the
partition type. The error position makes that clear.

This came up during the 9.3 merge. Passing InvalidOid to
deparse_context_for() will no longer work in 9.3, so we'd need to change
this somehow in the 9.3 merge, anyway.
上级 33fc5f17
......@@ -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,
......
......@@ -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;
......
......@@ -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
......
......@@ -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 */
......@@ -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.
......
......@@ -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"
......
......@@ -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"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册