77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.22 1999/08/05 02:33:53 tgl Exp $
10+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.23 1999/08/24 00:09:56 tgl Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -60,24 +60,24 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
6060 * whereas float-to-int type conversion will round to integer.
6161 */
6262Const * con = (Const * )node ;
63+ Const * newcon = makeNode (Const );
6364Type targetType = typeidType (targetTypeId );
64- char * val ;
6565
66- /* We know the source constant is really of type 'text' */
67- val = textout ((text * )con -> constvalue );
66+ newcon -> consttype = targetTypeId ;
67+ newcon -> constlen = typeLen (targetType );
68+ newcon -> constbyval = typeByVal (targetType );
69+ newcon -> constisnull = con -> constisnull ;
70+ newcon -> constisset = false;
6871
69- /* now make a new const node */
70- con = makeNode (Const );
71- con -> consttype = targetTypeId ;
72- con -> constlen = typeLen (targetType );
73- con -> constvalue = stringTypeDatum (targetType ,val ,atttypmod );
74- con -> constisnull = false;
75- con -> constbyval = typeByVal (targetType );
76- con -> constisset = false;
77-
78- pfree (val );
72+ if (!con -> constisnull )
73+ {
74+ /* We know the source constant is really of type 'text' */
75+ char * val = textout ((text * )con -> constvalue );
76+ newcon -> constvalue = stringTypeDatum (targetType ,val ,atttypmod );
77+ pfree (val );
78+ }
7979
80- result = (Node * )con ;
80+ result = (Node * )newcon ;
8181}
8282else
8383{
@@ -105,7 +105,7 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
105105 * such as coercing text 'now' to datetime? Need a way to
106106 * know whether type conversion function is cacheable...
107107 */
108- if (IsA (node ,Const ))
108+ if (IsA (node ,Const )&& ! (( Const * ) node ) -> constisnull )
109109{
110110Const * con = (Const * )node ;
111111Oid convertFuncid ;
@@ -122,9 +122,9 @@ coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId,
122122con = makeNode (Const );
123123con -> consttype = targetTypeId ;
124124con -> constlen = typeLen (targetType );
125+ con -> constbyval = typeByVal (targetType );
125126con -> constvalue = val ;
126127con -> constisnull = false;
127- con -> constbyval = typeByVal (targetType );
128128con -> constisset = false;
129129
130130result = (Node * )con ;