Pass atttypmod to CoerceTargetExpr, so that it can pass it on to
authorTom Lane
Mon, 17 Jan 2000 02:04:16 +0000 (02:04 +0000)
committerTom Lane
Mon, 17 Jan 2000 02:04:16 +0000 (02:04 +0000)
coerce_type, so that the right things happen when coercing a previously-
unknown constant to a destination data type.

src/backend/catalog/heap.c
src/backend/parser/parse_clause.c
src/backend/parser/parse_expr.c
src/backend/parser/parse_node.c
src/backend/parser/parse_target.c
src/backend/rewrite/rewriteHandler.c
src/include/parser/parse_target.h

index 83a4b420bbf40115796f31332c4879001511ef8f..0476f2c8223bc73c4fad0762ded612e0763717af 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.115 2000/01/16 19:57:00 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.116 2000/01/17 02:04:12 tgl Exp $
  *
  *
  * INTERFACE ROUTINES
@@ -1966,8 +1966,8 @@ AddRelationRawConstraints(Relation rel,
 
            if (type_id != atp->atttypid)
            {
-               if (CoerceTargetExpr(NULL, expr,
-                                    type_id, atp->atttypid) == NULL)
+               if (CoerceTargetExpr(NULL, expr, type_id,
+                                    atp->atttypid, atp->atttypmod) == NULL)
                    elog(ERROR, "Attribute '%s' is of type '%s'"
                         " but default expression is of type '%s'"
                         "\n\tYou will need to rewrite or cast the expression",
index 1f83150def10b6e606859c9451ef51d33a218a5a..0890ef7a630c7f09ef99090a84d2270dc911919d 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.48 1999/12/17 14:47:35 thomas Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/parse_clause.c,v 1.49 2000/01/17 02:04:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -757,7 +757,7 @@ transformUnionClause(List *unionClause, List *targetlist)
                    Node       *expr;
 
                    expr = ((TargetEntry *) lfirst(next_target))->expr;
-                   expr = CoerceTargetExpr(NULL, expr, itype, otype);
+                   expr = CoerceTargetExpr(NULL, expr, itype, otype, -1);
                    if (expr == NULL)
                    {
                        elog(ERROR, "Unable to transform %s to %s"
index 6fe43e9e0233f152a0d29b08af157849e9249890..d1e4460b6c08fb06d91e1d60362d01203e06776b 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.65 2000/01/17 00:14:48 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.66 2000/01/17 02:04:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -792,8 +792,8 @@ parser_typecast_expression(ParseState *pstate,
 
    if (inputType != targetType)
    {
-       expr = CoerceTargetExpr(pstate, expr,
-                               inputType, targetType);
+       expr = CoerceTargetExpr(pstate, expr, inputType,
+                               targetType, typename->typmod);
        if (expr == NULL)
            elog(ERROR, "Cannot cast type '%s' to '%s'",
                 typeidTypeName(inputType),
index 544a4462dd1def0a9ca6f667077f9718992dd609..0b48beb049155984e0aa4093f05887e0526b35fe 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.35 2000/01/15 02:59:32 petere Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/parse_node.c,v 1.36 2000/01/17 02:04:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -319,8 +319,8 @@ transformArraySubscripts(ParseState *pstate,
            {
                subexpr = transformExpr(pstate, ai->lidx, EXPR_COLUMN_FIRST);
                /* If it's not int4 already, try to coerce */
-               subexpr = CoerceTargetExpr(pstate, subexpr,
-                                          exprType(subexpr), INT4OID);
+               subexpr = CoerceTargetExpr(pstate, subexpr, exprType(subexpr),
+                                          INT4OID, -1);
                if (subexpr == NULL)
                    elog(ERROR, "array index expressions must be integers");
            }
@@ -339,8 +339,8 @@ transformArraySubscripts(ParseState *pstate,
        }
        subexpr = transformExpr(pstate, ai->uidx, EXPR_COLUMN_FIRST);
        /* If it's not int4 already, try to coerce */
-       subexpr = CoerceTargetExpr(pstate, subexpr,
-                                  exprType(subexpr), INT4OID);
+       subexpr = CoerceTargetExpr(pstate, subexpr, exprType(subexpr),
+                                  INT4OID, -1);
        if (subexpr == NULL)
            elog(ERROR, "array index expressions must be integers");
        upperIndexpr = lappend(upperIndexpr, subexpr);
@@ -358,8 +358,10 @@ transformArraySubscripts(ParseState *pstate,
        {
            if (typesource != typeneeded)
            {
+               /* XXX fixme: need to get the array's atttypmod? */
                assignFrom = CoerceTargetExpr(pstate, assignFrom,
-                                             typesource, typeneeded);
+                                             typesource, typeneeded,
+                                             -1);
                if (assignFrom == NULL)
                    elog(ERROR, "Array assignment requires type '%s'"
                         " but expression is of type '%s'"
index f80b6ef4fbb85bb71e043fc6f75e2ff3dd7c29d7..b6eb7e0b547413087f8e9a92957cc0c8c6393f8c 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.52 2000/01/17 00:14:48 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.53 2000/01/17 02:04:16 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -229,8 +229,8 @@ updateTargetListEntry(ParseState *pstate,
        {
            if (type_id != attrtype)
            {
-               tle->expr = CoerceTargetExpr(pstate, tle->expr,
-                                            type_id, attrtype);
+               tle->expr = CoerceTargetExpr(pstate, tle->expr, type_id,
+                                            attrtype, attrtypmod);
                if (tle->expr == NULL)
                    elog(ERROR, "Attribute '%s' is of type '%s'"
                         " but expression is of type '%s'"
@@ -264,10 +264,11 @@ Node *
 CoerceTargetExpr(ParseState *pstate,
                 Node *expr,
                 Oid type_id,
-                Oid attrtype)
+                Oid attrtype,
+                int32 attrtypmod)
 {
    if (can_coerce_type(1, &type_id, &attrtype))
-       expr = coerce_type(pstate, expr, type_id, attrtype, -1);
+       expr = coerce_type(pstate, expr, type_id, attrtype, attrtypmod);
 
 #ifndef DISABLE_STRING_HACKS
 
@@ -283,7 +284,7 @@ CoerceTargetExpr(ParseState *pstate,
        {
        }
        else if (can_coerce_type(1, &type_id, &text_id))
-           expr = coerce_type(pstate, expr, type_id, text_id, -1);
+           expr = coerce_type(pstate, expr, type_id, text_id, attrtypmod);
        else
            expr = NULL;
    }
index 101cd61bed165c3b3b8ed110278d3dabbac0bc54..dc8f2b832e7800c7632981020b6b2dce332e2697 100644 (file)
@@ -6,7 +6,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.64 2000/01/05 18:23:48 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteHandler.c,v 1.65 2000/01/17 02:04:13 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -1696,7 +1696,7 @@ check_targetlists_are_compatible(List *prev_target, List *current_target)
            Node       *expr;
 
            expr = ((TargetEntry *) lfirst(next_target))->expr;
-           expr = CoerceTargetExpr(NULL, expr, itype, otype);
+           expr = CoerceTargetExpr(NULL, expr, itype, otype, -1);
            if (expr == NULL)
            {
                elog(ERROR, "Unable to transform %s to %s"
index 08cf389d72e61671edcb3a2c4a78e8489f22b42d..022abd58520d75ad2eea08aa58915fbf0a9fe6d0 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: parse_target.h,v 1.16 1999/11/01 05:06:20 tgl Exp $
+ * $Id: parse_target.h,v 1.17 2000/01/17 02:04:15 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -23,7 +23,7 @@ extern void updateTargetListEntry(ParseState *pstate, TargetEntry *tle,
                                  char *colname, int attrno,
                                  List *indirection);
 extern Node *CoerceTargetExpr(ParseState *pstate, Node *expr,
-                             Oid type_id, Oid attrtype);
+                             Oid type_id, Oid attrtype, int32 attrtypmod);
 extern List *checkInsertTargets(ParseState *pstate, List *cols,
                                List **attrnos);