MCPcopy Create free account
hub / github.com/apache/cloudberry / transformTypeCast

Function transformTypeCast

src/backend/parser/parse_expr.c:2744–2821  ·  view source on GitHub ↗

* Handle an explicit CAST construct. * * Transform the argument, look up the type name, and apply any necessary * coercion function(s). */

Source from the content-addressed store, hash-verified

2742 * coercion function(s).
2743 */
2744static Node *
2745transformTypeCast(ParseState *pstate, TypeCast *tc)
2746{
2747 Node *result;
2748 Node *arg = tc->arg;
2749 Node *expr;
2750 Oid inputType;
2751 Oid targetType;
2752 int32 targetTypmod;
2753 int location;
2754
2755 /* Look up the type name first */
2756 typenameTypeIdAndMod(pstate, tc->typeName, &targetType, &targetTypmod);
2757
2758 /*
2759 * If the subject of the typecast is an ARRAY[] construct and the target
2760 * type is an array type, we invoke transformArrayExpr() directly so that
2761 * we can pass down the type information. This avoids some cases where
2762 * transformArrayExpr() might not infer the correct type. Otherwise, just
2763 * transform the argument normally.
2764 */
2765 if (IsA(arg, A_ArrayExpr))
2766 {
2767 Oid targetBaseType;
2768 int32 targetBaseTypmod;
2769 Oid elementType;
2770
2771 /*
2772 * If target is a domain over array, work with the base array type
2773 * here. Below, we'll cast the array type to the domain. In the
2774 * usual case that the target is not a domain, the remaining steps
2775 * will be a no-op.
2776 */
2777 targetBaseTypmod = targetTypmod;
2778 targetBaseType = getBaseTypeAndTypmod(targetType, &targetBaseTypmod);
2779 elementType = get_element_type(targetBaseType);
2780 if (OidIsValid(elementType))
2781 {
2782 expr = transformArrayExpr(pstate,
2783 (A_ArrayExpr *) arg,
2784 targetBaseType,
2785 elementType,
2786 targetBaseTypmod);
2787 }
2788 else
2789 expr = transformExprRecurse(pstate, arg);
2790 }
2791 else
2792 expr = transformExprRecurse(pstate, arg);
2793
2794 inputType = exprType(expr);
2795 if (inputType == InvalidOid)
2796 return expr; /* do nothing if NULL input */
2797
2798 /*
2799 * Location of the coercion is preferentially the location of the :: or
2800 * CAST symbol, but if there is none then use the location of the type
2801 * name (this can happen in TypeName 'string' syntax, for instance).

Callers 1

transformExprRecurseFunction · 0.85

Calls 11

typenameTypeIdAndModFunction · 0.85
getBaseTypeAndTypmodFunction · 0.85
get_element_typeFunction · 0.85
transformArrayExprFunction · 0.85
transformExprRecurseFunction · 0.85
exprTypeFunction · 0.85
coerce_to_target_typeFunction · 0.85
format_type_beFunction · 0.85
errcodeFunction · 0.50
errmsgFunction · 0.50

Tested by

no test coverage detected