diff options
author | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2009-11-13 19:48:26 +0000 |
---|---|---|
committer | Heikki Linnakangas <heikki.linnakangas@iki.fi> | 2009-11-13 19:48:26 +0000 |
commit | 30137bde6db48a8b8c1ffc736eb239bd7381f04d (patch) | |
tree | 18c907c6bfc7763da91971e253bd51808721345c /src | |
parent | 959af88533cf682a2522a78f99056bc8adf0b58c (diff) | |
download | postgresql-30137bde6db48a8b8c1ffc736eb239bd7381f04d.tar.gz postgresql-30137bde6db48a8b8c1ffc736eb239bd7381f04d.zip |
A better fix for the "ARRAY[...]::domain" problem. The previous patch worked,
but the transformed ArrayExpr claimed to have a return type of "domain",
even though the domain constraint was only checked by the enclosing
CoerceToDomain node. With this fix, the ArrayExpr is correctly labeled with
the base type of the domain. Per gripe by Tom Lane.
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/parser/parse_expr.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/src/backend/parser/parse_expr.c b/src/backend/parser/parse_expr.c index 9899d81df5f..36acd26f1cf 100644 --- a/src/backend/parser/parse_expr.c +++ b/src/backend/parser/parse_expr.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.241.2.3 2009/11/13 16:09:20 heikki Exp $ + * $PostgreSQL: pgsql/src/backend/parser/parse_expr.c,v 1.241.2.4 2009/11/13 19:48:26 heikki Exp $ * *------------------------------------------------------------------------- */ @@ -164,32 +164,23 @@ transformExpr(ParseState *pstate, Node *expr) elementType = get_element_type(targetType); if (OidIsValid(elementType)) { - result = transformArrayExpr(pstate, - (A_ArrayExpr *) tc->arg, - targetType, - elementType, - targetTypmod); - /* - * If the target array type is a domain, we still need - * to check the domain constraint. (coerce_to_domain - * is a no-op if targetType is not a domain) + * tranformArrayExpr doesn't know how to check domain + * constraints, so ask it to return the base type + * instead. transformTypeCast below will cast it to + * the domain. In the usual case that the target is + * not a domain, transformTypeCast is a no-op. */ - result = coerce_to_domain(result, - InvalidOid, - -1, - targetType, - COERCE_IMPLICIT_CAST, - tc->location, - false, - true); - break; + targetType = getBaseTypeAndTypmod(targetType, + &targetTypmod); + + tc = copyObject(tc); + tc->arg = transformArrayExpr(pstate, + (A_ArrayExpr *) tc->arg, + targetType, + elementType, + targetTypmod); } - - /* - * Corner case: ARRAY[] cast to a non-array type. Fall - * through to do it the standard way. - */ } result = transformTypeCast(pstate, tc); @@ -315,6 +306,7 @@ transformExpr(ParseState *pstate, Node *expr) case T_ArrayCoerceExpr: case T_ConvertRowtypeExpr: case T_CaseTestExpr: + case T_ArrayExpr: case T_CoerceToDomain: case T_CoerceToDomainValue: case T_SetToDefault: |