]> granicus.if.org Git - postgresql/blobdiff - src/backend/parser/parse_coerce.c
Modify all callers of datatype input and receive functions so that if these
[postgresql] / src / backend / parser / parse_coerce.c
index 8a950a643bd6f1976a84f70c1fa8b29f60b3cf96..5a343e768dda1a9492fb68f45a4c259e1ae88925 100644 (file)
@@ -3,12 +3,12 @@
  * parse_coerce.c
  *             handle type coercions/conversions for parser
  *
- * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  *
  * IDENTIFICATION
- *       $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.133 2005/11/22 18:17:16 momjian Exp $
+ *       $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.136 2006/04/04 19:35:34 tgl Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -166,26 +166,21 @@ coerce_type(ParseState *pstate, Node *node,
                newcon->constbyval = typeByVal(targetType);
                newcon->constisnull = con->constisnull;
 
+               /*
+                * We pass typmod -1 to the input routine, primarily because
+                * existing input routines follow implicit-coercion semantics for
+                * length checks, which is not always what we want here. Any
+                * length constraint will be applied later by our caller.
+                *
+                * We assume here that UNKNOWN's internal representation is the
+                * same as CSTRING.
+                */
                if (!con->constisnull)
-               {
-                       /*
-                        * We assume here that UNKNOWN's internal representation is the
-                        * same as CSTRING
-                        */
-                       char       *val = DatumGetCString(con->constvalue);
-
-                       /*
-                        * We pass typmod -1 to the input routine, primarily because
-                        * existing input routines follow implicit-coercion semantics for
-                        * length checks, which is not always what we want here. Any
-                        * length constraint will be applied later by our caller.
-                        *
-                        * Note that we call stringTypeDatum using the domain's pg_type
-                        * row, if it's a domain.  This works because the domain row has
-                        * the same typinput and typelem as the base type --- ugly...
-                        */
-                       newcon->constvalue = stringTypeDatum(targetType, val, -1);
-               }
+                       newcon->constvalue = stringTypeDatum(targetType,
+                                                                                       DatumGetCString(con->constvalue),
+                                                                                                -1);
+               else
+                       newcon->constvalue = stringTypeDatum(targetType, NULL, -1);
 
                result = (Node *) newcon;
 
@@ -243,7 +238,10 @@ coerce_type(ParseState *pstate, Node *node,
                }
 
                param->paramtype = targetTypeId;
-               return (Node *) param;
+
+               /* Apply domain constraints, if necessary */
+               return coerce_to_domain((Node *) param, InvalidOid, targetTypeId,
+                                                               cformat, false, false);
        }
        if (find_coercion_pathway(targetTypeId, inputTypeId, ccontext,
                                                          &funcId))