]> granicus.if.org Git - postgresql/blob - src/backend/parser/parse_coerce.c
Functions live in namespaces. Qualified function names work, eg
[postgresql] / src / backend / parser / parse_coerce.c
1 /*-------------------------------------------------------------------------
2  *
3  * parse_coerce.c
4  *              handle type coercions/conversions for parser
5  *
6  * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  *
10  * IDENTIFICATION
11  *        $Header: /cvsroot/pgsql/src/backend/parser/parse_coerce.c,v 2.69 2002/04/09 20:35:52 tgl Exp $
12  *
13  *-------------------------------------------------------------------------
14  */
15 #include "postgres.h"
16
17 #include "catalog/pg_proc.h"
18 #include "nodes/makefuncs.h"
19 #include "optimizer/clauses.h"
20 #include "parser/parse_coerce.h"
21 #include "parser/parse_expr.h"
22 #include "parser/parse_func.h"
23 #include "parser/parse_type.h"
24 #include "utils/builtins.h"
25 #include "utils/lsyscache.h"
26 #include "utils/syscache.h"
27
28
29 Oid                     DemoteType(Oid inType);
30 Oid                     PromoteTypeToNext(Oid inType);
31
32 static Oid      PreferredType(CATEGORY category, Oid type);
33 static Node *build_func_call(Oid funcid, Oid rettype, List *args);
34 static Oid      find_coercion_function(Oid targetTypeId, Oid inputTypeId,
35                                                                    Oid secondArgType);
36
37
38 /* coerce_type()
39  * Convert a function argument to a different type.
40  */
41 Node *
42 coerce_type(ParseState *pstate, Node *node, Oid inputTypeId,
43                         Oid targetTypeId, int32 atttypmod)
44 {
45         Node       *result;
46
47         if (targetTypeId == inputTypeId ||
48                 targetTypeId == InvalidOid ||
49                 node == NULL)
50         {
51                 /* no conversion needed */
52                 result = node;
53         }
54         else if (inputTypeId == UNKNOWNOID && IsA(node, Const))
55         {
56                 /*
57                  * Input is a string constant with previously undetermined type.
58                  * Apply the target type's typinput function to it to produce a
59                  * constant of the target type.
60                  *
61                  * NOTE: this case cannot be folded together with the other
62                  * constant-input case, since the typinput function does not
63                  * necessarily behave the same as a type conversion function. For
64                  * example, int4's typinput function will reject "1.2", whereas
65                  * float-to-int type conversion will round to integer.
66                  *
67                  * XXX if the typinput function is not cachable, we really ought to
68                  * postpone evaluation of the function call until runtime. But
69                  * there is no way to represent a typinput function call as an
70                  * expression tree, because C-string values are not Datums.
71                  */
72                 Const      *con = (Const *) node;
73                 Const      *newcon = makeNode(Const);
74                 Type            targetType = typeidType(targetTypeId);
75
76                 newcon->consttype = targetTypeId;
77                 newcon->constlen = typeLen(targetType);
78                 newcon->constbyval = typeByVal(targetType);
79                 newcon->constisnull = con->constisnull;
80                 newcon->constisset = false;
81
82                 if (!con->constisnull)
83                 {
84                         /* We know the source constant is really of type 'text' */
85                         char       *val = DatumGetCString(DirectFunctionCall1(textout,
86                                                                                                            con->constvalue));
87
88                         newcon->constvalue = stringTypeDatum(targetType, val, atttypmod);
89                         pfree(val);
90                 }
91
92                 ReleaseSysCache(targetType);
93
94                 result = (Node *) newcon;
95         }
96         else if (IsBinaryCompatible(inputTypeId, targetTypeId))
97         {
98                 /*
99                  * We don't really need to do a conversion, but we do need to
100                  * attach a RelabelType node so that the expression will be seen
101                  * to have the intended type when inspected by higher-level code.
102                  *
103                  * XXX could we label result with exprTypmod(node) instead of
104                  * default -1 typmod, to save a possible length-coercion later?
105                  * Would work if both types have same interpretation of typmod,
106                  * which is likely but not certain.
107                  */
108                 result = (Node *) makeRelabelType(node, targetTypeId, -1);
109         }
110         else if (typeInheritsFrom(inputTypeId, targetTypeId))
111         {
112                 /*
113                  * Input class type is a subclass of target, so nothing to do
114                  * --- except relabel the type.  This is binary compatibility
115                  * for complex types.
116                  */
117                 result = (Node *) makeRelabelType(node, targetTypeId, -1);
118         }
119         else
120         {
121                 /*
122                  * Otherwise, find the appropriate type conversion function
123                  * (caller should have determined that there is one), and generate
124                  * an expression tree representing run-time application of the
125                  * conversion function.
126                  *
127                  * For domains, we use the coercion function for the base type.
128                  */
129                 Oid                     baseTypeId = getBaseType(targetTypeId);
130                 Oid                     funcId;
131
132                 funcId = find_coercion_function(baseTypeId,
133                                                                                 getBaseType(inputTypeId),
134                                                                                 InvalidOid);
135                 if (!OidIsValid(funcId))
136                         elog(ERROR, "coerce_type: no conversion function from %s to %s",
137                                  format_type_be(inputTypeId), format_type_be(targetTypeId));
138
139                 result = build_func_call(funcId, baseTypeId, makeList1(node));
140
141                 /* if domain, relabel with domain type ID */
142                 if (targetTypeId != baseTypeId)
143                         result = (Node *) makeRelabelType(result, targetTypeId, -1);
144
145                 /*
146                  * If the input is a constant, apply the type conversion function
147                  * now instead of delaying to runtime.  (We could, of course, just
148                  * leave this to be done during planning/optimization; but it's a
149                  * very frequent special case, and we save cycles in the rewriter
150                  * if we fold the expression now.)
151                  *
152                  * Note that no folding will occur if the conversion function is not
153                  * marked 'iscachable'.
154                  *
155                  * HACK: if constant is NULL, don't fold it here.  This is needed by
156                  * make_subplan(), which calls this routine on placeholder Const
157                  * nodes that mustn't be collapsed.  (It'd be a lot cleaner to
158                  * make a separate node type for that purpose...)
159                  */
160                 if (IsA(node, Const) &&
161                         !((Const *) node)->constisnull)
162                         result = eval_const_expressions(result);
163         }
164
165         return result;
166 }
167
168
169 /* can_coerce_type()
170  * Can input_typeids be coerced to func_typeids?
171  *
172  * There are a few types which are known apriori to be convertible.
173  * We will check for those cases first, and then look for possible
174  *      conversion functions.
175  *
176  * Notes:
177  * This uses the same mechanism as the CAST() SQL construct in gram.y.
178  */
179 bool
180 can_coerce_type(int nargs, Oid *input_typeids, Oid *func_typeids)
181 {
182         int                     i;
183
184         /* run through argument list... */
185         for (i = 0; i < nargs; i++)
186         {
187                 Oid                     inputTypeId = input_typeids[i];
188                 Oid                     targetTypeId = func_typeids[i];
189                 Oid                     funcId;
190
191                 /* no problem if same type */
192                 if (inputTypeId == targetTypeId)
193                         continue;
194
195                 /*
196                  * one of the known-good transparent conversions? then drop
197                  * through...
198                  */
199                 if (IsBinaryCompatible(inputTypeId, targetTypeId))
200                         continue;
201
202                 /* don't know what to do for the output type? then quit... */
203                 if (targetTypeId == InvalidOid)
204                         return false;
205                 /* don't know what to do for the input type? then quit... */
206                 if (inputTypeId == InvalidOid)
207                         return false;
208
209                 /*
210                  * If input is an untyped string constant, assume we can convert
211                  * it to anything except a class type.
212                  */
213                 if (inputTypeId == UNKNOWNOID)
214                 {
215                         if (ISCOMPLEX(targetTypeId))
216                                 return false;
217                         continue;
218                 }
219
220                 /*
221                  * If input is a class type that inherits from target, no problem
222                  */
223                 if (typeInheritsFrom(inputTypeId, targetTypeId))
224                         continue;
225
226                 /* don't choke on references to no-longer-existing types */
227                 if (!typeidIsValid(inputTypeId))
228                         return false;
229                 if (!typeidIsValid(targetTypeId))
230                         return false;
231
232                 /*
233                  * Else, try for explicit conversion using functions: look for a
234                  * single-argument function named with the target type name and
235                  * accepting the source type.
236                  *
237                  * If either type is a domain, use its base type instead.
238                  */
239                 funcId = find_coercion_function(getBaseType(targetTypeId),
240                                                                                 getBaseType(inputTypeId),
241                                                                                 InvalidOid);
242                 if (!OidIsValid(funcId))
243                         return false;
244         }
245
246         return true;
247 }
248
249 /* coerce_type_typmod()
250  * Force a value to a particular typmod, if meaningful and possible.
251  *
252  * This is applied to values that are going to be stored in a relation
253  * (where we have an atttypmod for the column) as well as values being
254  * explicitly CASTed (where the typmod comes from the target type spec).
255  *
256  * The caller must have already ensured that the value is of the correct
257  * type, typically by applying coerce_type.
258  *
259  * If the target column type possesses a function named for the type
260  * and having parameter signature (columntype, int4), we assume that
261  * the type requires coercion to its own length and that the said
262  * function should be invoked to do that.
263  *
264  * "bpchar" (ie, char(N)) and "numeric" are examples of such types.
265  */
266 Node *
267 coerce_type_typmod(ParseState *pstate, Node *node,
268                                    Oid targetTypeId, int32 atttypmod)
269 {
270         Oid                     baseTypeId;
271         Oid                     funcId;
272
273         /*
274          * A negative typmod is assumed to mean that no coercion is wanted.
275          */
276         if (atttypmod < 0 || atttypmod == exprTypmod(node))
277                 return node;
278
279         /* If given type is a domain, use base type instead */
280         baseTypeId = getBaseType(targetTypeId);
281
282         funcId = find_coercion_function(baseTypeId, baseTypeId, INT4OID);
283
284         if (OidIsValid(funcId))
285         {
286                 Const      *cons;
287
288                 cons = makeConst(INT4OID,
289                                                  sizeof(int32),
290                                                  Int32GetDatum(atttypmod),
291                                                  false,
292                                                  true,
293                                                  false,
294                                                  false);
295
296                 node = build_func_call(funcId, baseTypeId, makeList2(node, cons));
297
298                 /* relabel if it's domain case */
299                 if (targetTypeId != baseTypeId)
300                         node = (Node *) makeRelabelType(node, targetTypeId, atttypmod);
301         }
302
303         return node;
304 }
305
306
307 /* coerce_to_boolean()
308  *              Coerce an argument of a construct that requires boolean input
309  *              (AND, OR, NOT, etc).
310  *
311  * If successful, update *pnode to be the transformed argument (if any
312  * transformation is needed), and return TRUE.  If fail, return FALSE.
313  * (The caller must check for FALSE and emit a suitable error message.)
314  */
315 bool
316 coerce_to_boolean(ParseState *pstate, Node **pnode)
317 {
318         Oid                     inputTypeId = exprType(*pnode);
319         Oid                     targetTypeId;
320
321         if (inputTypeId == BOOLOID)
322                 return true;                    /* no work */
323         targetTypeId = BOOLOID;
324         if (!can_coerce_type(1, &inputTypeId, &targetTypeId))
325                 return false;                   /* fail, but let caller choose error msg */
326         *pnode = coerce_type(pstate, *pnode, inputTypeId, targetTypeId, -1);
327         return true;
328 }
329
330
331 /* select_common_type()
332  *              Determine the common supertype of a list of input expression types.
333  *              This is used for determining the output type of CASE and UNION
334  *              constructs.
335  *
336  * typeids is a nonempty integer list of type OIDs.  Note that earlier items
337  * in the list will be preferred if there is doubt.
338  * 'context' is a phrase to use in the error message if we fail to select
339  * a usable type.
340  *
341  * XXX this code is WRONG, since (for example) given the input (int4,int8)
342  * it will select int4, whereas according to SQL92 clause 9.3 the correct
343  * answer is clearly int8.      To fix this we need a notion of a promotion
344  * hierarchy within type categories --- something more complete than
345  * just a single preferred type.
346  */
347 Oid
348 select_common_type(List *typeids, const char *context)
349 {
350         Oid                     ptype;
351         CATEGORY        pcategory;
352         List       *l;
353
354         Assert(typeids != NIL);
355         ptype = (Oid) lfirsti(typeids);
356         pcategory = TypeCategory(ptype);
357         foreach(l, lnext(typeids))
358         {
359                 Oid                     ntype = (Oid) lfirsti(l);
360
361                 /* move on to next one if no new information... */
362                 if ((ntype != InvalidOid) && (ntype != UNKNOWNOID) && (ntype != ptype))
363                 {
364                         if ((ptype == InvalidOid) || ptype == UNKNOWNOID)
365                         {
366                                 /* so far, only nulls so take anything... */
367                                 ptype = ntype;
368                                 pcategory = TypeCategory(ptype);
369                         }
370                         else if (TypeCategory(ntype) != pcategory)
371                         {
372                                 /*
373                                  * both types in different categories? then not much
374                                  * hope...
375                                  */
376                                 elog(ERROR, "%s types \"%s\" and \"%s\" not matched",
377                                   context, typeidTypeName(ptype), typeidTypeName(ntype));
378                         }
379                         else if (IsPreferredType(pcategory, ntype)
380                                          && !IsPreferredType(pcategory, ptype)
381                                          && can_coerce_type(1, &ptype, &ntype))
382                         {
383                                 /*
384                                  * new one is preferred and can convert? then take it...
385                                  */
386                                 ptype = ntype;
387                                 pcategory = TypeCategory(ptype);
388                         }
389                 }
390         }
391
392         /*
393          * If all the inputs were UNKNOWN type --- ie, unknown-type literals
394          * --- then resolve as type TEXT.  This situation comes up with
395          * constructs like SELECT (CASE WHEN foo THEN 'bar' ELSE 'baz' END);
396          * SELECT 'foo' UNION SELECT 'bar'; It might seem desirable to leave
397          * the construct's output type as UNKNOWN, but that really doesn't
398          * work, because we'd probably end up needing a runtime coercion from
399          * UNKNOWN to something else, and we usually won't have it.  We need
400          * to coerce the unknown literals while they are still literals, so a
401          * decision has to be made now.
402          */
403         if (ptype == UNKNOWNOID)
404                 ptype = TEXTOID;
405
406         return ptype;
407 }
408
409 /* coerce_to_common_type()
410  *              Coerce an expression to the given type.
411  *
412  * This is used following select_common_type() to coerce the individual
413  * expressions to the desired type.  'context' is a phrase to use in the
414  * error message if we fail to coerce.
415  *
416  * NOTE: pstate may be NULL.
417  */
418 Node *
419 coerce_to_common_type(ParseState *pstate, Node *node,
420                                           Oid targetTypeId,
421                                           const char *context)
422 {
423         Oid                     inputTypeId = exprType(node);
424
425         if (inputTypeId == targetTypeId)
426                 return node;                    /* no work */
427         if (can_coerce_type(1, &inputTypeId, &targetTypeId))
428                 node = coerce_type(pstate, node, inputTypeId, targetTypeId, -1);
429         else
430         {
431                 elog(ERROR, "%s unable to convert to type \"%s\"",
432                          context, typeidTypeName(targetTypeId));
433         }
434         return node;
435 }
436
437
438 /* TypeCategory()
439  * Assign a category to the specified OID.
440  * XXX This should be moved to system catalog lookups
441  * to allow for better type extensibility.
442  * - thomas 2001-09-30
443  */
444 CATEGORY
445 TypeCategory(Oid inType)
446 {
447         CATEGORY        result;
448
449         switch (inType)
450         {
451                 case (BOOLOID):
452                         result = BOOLEAN_TYPE;
453                         break;
454
455                 case (CHAROID):
456                 case (NAMEOID):
457                 case (BPCHAROID):
458                 case (VARCHAROID):
459                 case (TEXTOID):
460                         result = STRING_TYPE;
461                         break;
462
463                 case (BITOID):
464                 case (VARBITOID):
465                         result = BITSTRING_TYPE;
466                         break;
467
468                 case (OIDOID):
469                 case (REGPROCOID):
470                 case (INT2OID):
471                 case (INT4OID):
472                 case (INT8OID):
473                 case (FLOAT4OID):
474                 case (FLOAT8OID):
475                 case (NUMERICOID):
476                 case (CASHOID):
477                         result = NUMERIC_TYPE;
478                         break;
479
480                 case (DATEOID):
481                 case (TIMEOID):
482                 case (TIMETZOID):
483                 case (ABSTIMEOID):
484                 case (TIMESTAMPOID):
485                 case (TIMESTAMPTZOID):
486                         result = DATETIME_TYPE;
487                         break;
488
489                 case (RELTIMEOID):
490                 case (TINTERVALOID):
491                 case (INTERVALOID):
492                         result = TIMESPAN_TYPE;
493                         break;
494
495                 case (POINTOID):
496                 case (LSEGOID):
497                 case (PATHOID):
498                 case (BOXOID):
499                 case (POLYGONOID):
500                 case (LINEOID):
501                 case (CIRCLEOID):
502                         result = GEOMETRIC_TYPE;
503                         break;
504
505                 case (INETOID):
506                 case (CIDROID):
507                         result = NETWORK_TYPE;
508                         break;
509
510                 case (UNKNOWNOID):
511                 case (InvalidOid):
512                         result = UNKNOWN_TYPE;
513                         break;
514
515                 default:
516                         result = USER_TYPE;
517                         break;
518         }
519         return result;
520 }       /* TypeCategory() */
521
522
523 /* IsBinaryCompatible()
524  *              Check if two types are binary-compatible.
525  *
526  * This notion allows us to cheat and directly exchange values without
527  * going through the trouble of calling a conversion function.
528  *
529  * XXX This should be moved to system catalog lookups
530  * to allow for better type extensibility.
531  */
532
533 /*
534  * This macro describes hard-coded knowledge of binary compatibility
535  * for built-in types.
536  */
537 #define IS_BINARY_COMPATIBLE(a,b) \
538                   (((a) == BPCHAROID && (b) == TEXTOID) \
539                 || ((a) == BPCHAROID && (b) == VARCHAROID) \
540                 || ((a) == VARCHAROID && (b) == TEXTOID) \
541                 || ((a) == VARCHAROID && (b) == BPCHAROID) \
542                 || ((a) == TEXTOID && (b) == BPCHAROID) \
543                 || ((a) == TEXTOID && (b) == VARCHAROID) \
544                 || ((a) == OIDOID && (b) == INT4OID) \
545                 || ((a) == OIDOID && (b) == REGPROCOID) \
546                 || ((a) == INT4OID && (b) == OIDOID) \
547                 || ((a) == INT4OID && (b) == REGPROCOID) \
548                 || ((a) == REGPROCOID && (b) == OIDOID) \
549                 || ((a) == REGPROCOID && (b) == INT4OID) \
550                 || ((a) == ABSTIMEOID && (b) == INT4OID) \
551                 || ((a) == INT4OID && (b) == ABSTIMEOID) \
552                 || ((a) == RELTIMEOID && (b) == INT4OID) \
553                 || ((a) == INT4OID && (b) == RELTIMEOID) \
554                 || ((a) == INETOID && (b) == CIDROID) \
555                 || ((a) == CIDROID && (b) == INETOID) \
556                 || ((a) == BITOID && (b) == VARBITOID) \
557                 || ((a) == VARBITOID && (b) == BITOID))
558
559 bool
560 IsBinaryCompatible(Oid type1, Oid type2)
561 {
562         if (type1 == type2)
563                 return true;
564         if (IS_BINARY_COMPATIBLE(type1, type2))
565                 return true;
566         /*
567          * Perhaps the types are domains; if so, look at their base types
568          */
569         if (OidIsValid(type1))
570                 type1 = getBaseType(type1);
571         if (OidIsValid(type2))
572                 type2 = getBaseType(type2);
573         if (type1 == type2)
574                 return true;
575         if (IS_BINARY_COMPATIBLE(type1, type2))
576                 return true;
577         return false;
578 }
579
580
581 /* IsPreferredType()
582  * Check if this type is a preferred type.
583  * XXX This should be moved to system catalog lookups
584  * to allow for better type extensibility.
585  * - thomas 2001-09-30
586  */
587 bool
588 IsPreferredType(CATEGORY category, Oid type)
589 {
590         return (type == PreferredType(category, type));
591 }       /* IsPreferredType() */
592
593
594 /* PreferredType()
595  * Return the preferred type OID for the specified category.
596  * XXX This should be moved to system catalog lookups
597  * to allow for better type extensibility.
598  * - thomas 2001-09-30
599  */
600 static Oid
601 PreferredType(CATEGORY category, Oid type)
602 {
603         Oid                     result;
604
605         switch (category)
606         {
607                 case (BOOLEAN_TYPE):
608                         result = BOOLOID;
609                         break;
610
611                 case (STRING_TYPE):
612                         result = TEXTOID;
613                         break;
614
615                 case (BITSTRING_TYPE):
616                         result = VARBITOID;
617                         break;
618
619                 case (NUMERIC_TYPE):
620                         if (type == OIDOID)
621                                 result = OIDOID;
622                         else if (type == NUMERICOID)
623                                 result = NUMERICOID;
624                         else
625                                 result = FLOAT8OID;
626                         break;
627
628                 case (DATETIME_TYPE):
629                         if (type == DATEOID)
630                                 result = TIMESTAMPOID;
631                         else
632                                 result = TIMESTAMPTZOID;
633                         break;
634
635                 case (TIMESPAN_TYPE):
636                         result = INTERVALOID;
637                         break;
638
639                 case (NETWORK_TYPE):
640                         result = INETOID;
641                         break;
642
643                 case (GEOMETRIC_TYPE):
644                 case (USER_TYPE):
645                         result = type;
646                         break;
647
648                 default:
649                         result = UNKNOWNOID;
650                         break;
651         }
652         return result;
653 }       /* PreferredType() */
654
655 /*
656  * find_coercion_function
657  *              Look for a coercion function between two types.
658  *
659  * A coercion function must be named after (the internal name of) its
660  * result type, and must accept exactly the specified input type.  We
661  * also require it to be defined in the same namespace as its result type.
662  *
663  * This routine is also used to look for length-coercion functions, which
664  * are similar but accept a second argument.  secondArgType is the type
665  * of the second argument (normally INT4OID), or InvalidOid if we are
666  * looking for a regular coercion function.
667  *
668  * If a function is found, return its pg_proc OID; else return InvalidOid.
669  */
670 static Oid
671 find_coercion_function(Oid targetTypeId, Oid inputTypeId, Oid secondArgType)
672 {
673         Type            targetType;
674         char       *typname;
675         Oid                     typnamespace;
676         Oid                     oid_array[FUNC_MAX_ARGS];
677         int                     nargs;
678         HeapTuple       ftup;
679         Form_pg_proc pform;
680         Oid                     funcid;
681
682         targetType = typeidType(targetTypeId);
683         typname = NameStr(((Form_pg_type) GETSTRUCT(targetType))->typname);
684         typnamespace = ((Form_pg_type) GETSTRUCT(targetType))->typnamespace;
685
686         MemSet(oid_array, 0, FUNC_MAX_ARGS * sizeof(Oid));
687         oid_array[0] = inputTypeId;
688         if (OidIsValid(secondArgType))
689         {
690                 oid_array[1] = secondArgType;
691                 nargs = 2;
692         }
693         else
694                 nargs = 1;
695
696         ftup = SearchSysCache(PROCNAMENSP,
697                                                   CStringGetDatum(typname),
698                                                   Int16GetDatum(nargs),
699                                                   PointerGetDatum(oid_array),
700                                                   ObjectIdGetDatum(typnamespace));
701         if (!HeapTupleIsValid(ftup))
702         {
703                 ReleaseSysCache(targetType);
704                 return InvalidOid;
705         }
706         /* Make sure the function's result type is as expected, too */
707         pform = (Form_pg_proc) GETSTRUCT(ftup);
708         if (pform->prorettype != targetTypeId)
709         {
710                 ReleaseSysCache(ftup);
711                 ReleaseSysCache(targetType);
712                 return InvalidOid;
713         }
714         funcid = ftup->t_data->t_oid;
715         ReleaseSysCache(ftup);
716         ReleaseSysCache(targetType);
717         return funcid;
718 }
719
720 /*
721  * Build an expression tree representing a function call.
722  *
723  * The argument expressions must have been transformed already.
724  */
725 static Node *
726 build_func_call(Oid funcid, Oid rettype, List *args)
727 {
728         Func       *funcnode;
729         Expr       *expr;
730
731         funcnode = makeNode(Func);
732         funcnode->funcid = funcid;
733         funcnode->functype = rettype;
734         funcnode->func_fcache = NULL;
735
736         expr = makeNode(Expr);
737         expr->typeOid = rettype;
738         expr->opType = FUNC_EXPR;
739         expr->oper = (Node *) funcnode;
740         expr->args = args;
741
742         return (Node *) expr;
743 }