PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeFuncs.c File Reference
#include "postgres.h"
#include "catalog/pg_collation.h"
#include "catalog/pg_type.h"
#include "miscadmin.h"
#include "nodes/execnodes.h"
#include "nodes/nodeFuncs.h"
#include "nodes/pathnodes.h"
#include "utils/builtins.h"
#include "utils/lsyscache.h"
Include dependency graph for nodeFuncs.c:

Go to the source code of this file.

Macros

#define WALK(n)   walker((Node *) (n), context)
 
#define LIST_WALK(l)   expression_tree_walker_impl((Node *) (l), walker, context)
 
#define FLATCOPY(newnode, node, nodetype)
 
#define MUTATE(newfield, oldfield, fieldtype)    ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
 
#define PSWALK(n)   walker(n, context)
 

Functions

static bool expression_returns_set_walker (Node *node, void *context)
 
static int leftmostLoc (int loc1, int loc2)
 
static bool fix_opfuncids_walker (Node *node, void *context)
 
static bool planstate_walk_subplans (List *plans, planstate_tree_walker_callback walker, void *context)
 
static bool planstate_walk_members (PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
 
Oid exprType (const Node *expr)
 
int32 exprTypmod (const Node *expr)
 
bool exprIsLengthCoercion (const Node *expr, int32 *coercedTypmod)
 
NodeapplyRelabelType (Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
 
Noderelabel_to_typmod (Node *expr, int32 typmod)
 
Nodestrip_implicit_coercions (Node *node)
 
bool expression_returns_set (Node *clause)
 
Oid exprCollation (const Node *expr)
 
Oid exprInputCollation (const Node *expr)
 
void exprSetCollation (Node *expr, Oid collation)
 
void exprSetInputCollation (Node *expr, Oid inputcollation)
 
int exprLocation (const Node *expr)
 
void fix_opfuncids (Node *node)
 
void set_opfuncid (OpExpr *opexpr)
 
void set_sa_opfuncid (ScalarArrayOpExpr *opexpr)
 
bool check_functions_in_node (Node *node, check_function_callback checker, void *context)
 
bool expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
bool query_tree_walker_impl (Query *query, tree_walker_callback walker, void *context, int flags)
 
bool range_table_walker_impl (List *rtable, tree_walker_callback walker, void *context, int flags)
 
bool range_table_entry_walker_impl (RangeTblEntry *rte, tree_walker_callback walker, void *context, int flags)
 
Nodeexpression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context)
 
Queryquery_tree_mutator_impl (Query *query, tree_mutator_callback mutator, void *context, int flags)
 
Listrange_table_mutator_impl (List *rtable, tree_mutator_callback mutator, void *context, int flags)
 
bool query_or_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context, int flags)
 
Nodequery_or_expression_tree_mutator_impl (Node *node, tree_mutator_callback mutator, void *context, int flags)
 
bool raw_expression_tree_walker_impl (Node *node, tree_walker_callback walker, void *context)
 
bool planstate_tree_walker_impl (PlanState *planstate, planstate_tree_walker_callback walker, void *context)
 

Macro Definition Documentation

◆ FLATCOPY

#define FLATCOPY (   newnode,
  node,
  nodetype 
)
Value:
memcpy((newnode), (node), sizeof(nodetype)) )
#define palloc_object(type)
Definition fe_memutils.h:74
static int fb(int x)

◆ LIST_WALK

#define LIST_WALK (   l)    expression_tree_walker_impl((Node *) (l), walker, context)

◆ MUTATE

#define MUTATE (   newfield,
  oldfield,
  fieldtype 
)     ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )

◆ PSWALK

#define PSWALK (   n)    walker(n, context)

◆ WALK

#define WALK (   n)    walker((Node *) (n), context)

Function Documentation

◆ applyRelabelType()

Node * applyRelabelType ( Node arg,
Oid  rtype,
int32  rtypmod,
Oid  rcollid,
CoercionForm  rformat,
int  rlocation,
bool  overwrite_ok 
)

Definition at line 641 of file nodeFuncs.c.

643{
644 /*
645 * If we find stacked RelabelTypes (eg, from foo::int::oid) we can discard
646 * all but the top one, and must do so to ensure that semantically
647 * equivalent expressions are equal().
648 */
649 while (arg && IsA(arg, RelabelType))
650 arg = (Node *) ((RelabelType *) arg)->arg;
651
652 if (arg && IsA(arg, Const))
653 {
654 /* Modify the Const directly to preserve const-flatness. */
655 Const *con = (Const *) arg;
656
657 if (!overwrite_ok)
658 con = copyObject(con);
659 con->consttype = rtype;
660 con->consttypmod = rtypmod;
661 con->constcollid = rcollid;
662 /* We keep the Const's original location. */
663 return (Node *) con;
664 }
665 else if (exprType(arg) == rtype &&
666 exprTypmod(arg) == rtypmod &&
668 {
669 /* Sometimes we find a nest of relabels that net out to nothing. */
670 return arg;
671 }
672 else
673 {
674 /* Nope, gotta have a RelabelType. */
676
677 newrelabel->arg = (Expr *) arg;
678 newrelabel->resulttype = rtype;
679 newrelabel->resulttypmod = rtypmod;
680 newrelabel->resultcollid = rcollid;
681 newrelabel->relabelformat = rformat;
682 newrelabel->location = rlocation;
683 return (Node *) newrelabel;
684 }
685}
Datum arg
Definition elog.c:1323
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42
int32 exprTypmod(const Node *expr)
Definition nodeFuncs.c:304
Oid exprCollation(const Node *expr)
Definition nodeFuncs.c:826
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define copyObject(obj)
Definition nodes.h:232
#define makeNode(_type_)
Definition nodes.h:161
Oid consttype
Definition primnodes.h:330
Definition nodes.h:135

References arg, Const::consttype, copyObject, exprCollation(), exprType(), exprTypmod(), fb(), IsA, and makeNode.

Referenced by canonicalize_ec_expression(), coerce_type_typmod(), eval_const_expressions_mutator(), generate_setop_tlist(), and relabel_to_typmod().

◆ check_functions_in_node()

bool check_functions_in_node ( Node node,
check_function_callback  checker,
void context 
)

Definition at line 1928 of file nodeFuncs.c.

1930{
1931 switch (nodeTag(node))
1932 {
1933 case T_Aggref:
1934 {
1935 Aggref *expr = (Aggref *) node;
1936
1937 if (checker(expr->aggfnoid, context))
1938 return true;
1939 }
1940 break;
1941 case T_WindowFunc:
1942 {
1943 WindowFunc *expr = (WindowFunc *) node;
1944
1945 if (checker(expr->winfnoid, context))
1946 return true;
1947 }
1948 break;
1949 case T_FuncExpr:
1950 {
1951 FuncExpr *expr = (FuncExpr *) node;
1952
1953 if (checker(expr->funcid, context))
1954 return true;
1955 }
1956 break;
1957 case T_OpExpr:
1958 case T_DistinctExpr: /* struct-equivalent to OpExpr */
1959 case T_NullIfExpr: /* struct-equivalent to OpExpr */
1960 {
1961 OpExpr *expr = (OpExpr *) node;
1962
1963 /* Set opfuncid if it wasn't set already */
1964 set_opfuncid(expr);
1965 if (checker(expr->opfuncid, context))
1966 return true;
1967 }
1968 break;
1970 {
1971 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
1972
1973 set_sa_opfuncid(expr);
1974 if (checker(expr->opfuncid, context))
1975 return true;
1976 }
1977 break;
1978 case T_CoerceViaIO:
1979 {
1980 CoerceViaIO *expr = (CoerceViaIO *) node;
1981 Oid iofunc;
1982 Oid typioparam;
1983 bool typisvarlena;
1984
1985 /* check the result type's input function */
1987 &iofunc, &typioparam);
1988 if (checker(iofunc, context))
1989 return true;
1990 /* check the input type's output function */
1992 &iofunc, &typisvarlena);
1993 if (checker(iofunc, context))
1994 return true;
1995 }
1996 break;
1997 case T_RowCompareExpr:
1998 {
2000 ListCell *opid;
2001
2002 foreach(opid, rcexpr->opnos)
2003 {
2005
2006 if (checker(opfuncid, context))
2007 return true;
2008 }
2009 }
2010 break;
2011 default:
2012 break;
2013 }
2014 return false;
2015}
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Definition lsyscache.c:3102
RegProcedure get_opcode(Oid opno)
Definition lsyscache.c:1478
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
Definition lsyscache.c:3069
void set_sa_opfuncid(ScalarArrayOpExpr *opexpr)
Definition nodeFuncs.c:1901
void set_opfuncid(OpExpr *opexpr)
Definition nodeFuncs.c:1890
#define nodeTag(nodeptr)
Definition nodes.h:139
#define lfirst_oid(lc)
Definition pg_list.h:174
unsigned int Oid
Oid aggfnoid
Definition primnodes.h:464
Oid funcid
Definition primnodes.h:783

References Aggref::aggfnoid, CoerceViaIO::arg, exprType(), fb(), FuncExpr::funcid, get_opcode(), getTypeInputInfo(), getTypeOutputInfo(), lfirst_oid, nodeTag, CoerceViaIO::resulttype, set_opfuncid(), set_sa_opfuncid(), and WindowFunc::winfnoid.

Referenced by check_simple_rowfilter_expr_walker(), check_virtual_generated_security_walker(), contain_leaked_vars_walker(), contain_mutable_functions_walker(), contain_nonstrict_functions_walker(), contain_volatile_functions_not_nextval_walker(), contain_volatile_functions_walker(), and max_parallel_hazard_walker().

◆ exprCollation()

Oid exprCollation ( const Node expr)

Definition at line 826 of file nodeFuncs.c.

827{
828 Oid coll;
829
830 if (!expr)
831 return InvalidOid;
832
833 switch (nodeTag(expr))
834 {
835 case T_Var:
836 coll = ((const Var *) expr)->varcollid;
837 break;
838 case T_Const:
839 coll = ((const Const *) expr)->constcollid;
840 break;
841 case T_Param:
842 coll = ((const Param *) expr)->paramcollid;
843 break;
844 case T_Aggref:
845 coll = ((const Aggref *) expr)->aggcollid;
846 break;
847 case T_GroupingFunc:
849 break;
850 case T_WindowFunc:
851 coll = ((const WindowFunc *) expr)->wincollid;
852 break;
854 coll = ((const MergeSupportFunc *) expr)->msfcollid;
855 break;
857 coll = ((const SubscriptingRef *) expr)->refcollid;
858 break;
859 case T_FuncExpr:
860 coll = ((const FuncExpr *) expr)->funccollid;
861 break;
862 case T_NamedArgExpr:
863 coll = exprCollation((Node *) ((const NamedArgExpr *) expr)->arg);
864 break;
865 case T_OpExpr:
866 coll = ((const OpExpr *) expr)->opcollid;
867 break;
868 case T_DistinctExpr:
869 coll = ((const DistinctExpr *) expr)->opcollid;
870 break;
871 case T_NullIfExpr:
872 coll = ((const NullIfExpr *) expr)->opcollid;
873 break;
875 /* ScalarArrayOpExpr's result is boolean ... */
876 coll = InvalidOid; /* ... so it has no collation */
877 break;
878 case T_BoolExpr:
879 /* BoolExpr's result is boolean ... */
880 coll = InvalidOid; /* ... so it has no collation */
881 break;
882 case T_SubLink:
883 {
884 const SubLink *sublink = (const SubLink *) expr;
885
886 if (sublink->subLinkType == EXPR_SUBLINK ||
887 sublink->subLinkType == ARRAY_SUBLINK)
888 {
889 /* get the collation of subselect's first target column */
890 Query *qtree = (Query *) sublink->subselect;
892
893 if (!qtree || !IsA(qtree, Query))
894 elog(ERROR, "cannot get collation for untransformed sublink");
895 tent = linitial_node(TargetEntry, qtree->targetList);
896 Assert(!tent->resjunk);
897 coll = exprCollation((Node *) tent->expr);
898 /* collation doesn't change if it's converted to array */
899 }
900 else
901 {
902 /* otherwise, SubLink's result is RECORD or BOOLEAN */
903 coll = InvalidOid; /* ... so it has no collation */
904 }
905 }
906 break;
907 case T_SubPlan:
908 {
909 const SubPlan *subplan = (const SubPlan *) expr;
910
911 if (subplan->subLinkType == EXPR_SUBLINK ||
912 subplan->subLinkType == ARRAY_SUBLINK)
913 {
914 /* get the collation of subselect's first target column */
915 coll = subplan->firstColCollation;
916 /* collation doesn't change if it's converted to array */
917 }
918 else
919 {
920 /* otherwise, SubPlan's result is RECORD or BOOLEAN */
921 coll = InvalidOid; /* ... so it has no collation */
922 }
923 }
924 break;
926 {
927 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
928
929 /* subplans should all return the same thing */
930 coll = exprCollation((Node *) linitial(asplan->subplans));
931 }
932 break;
933 case T_FieldSelect:
934 coll = ((const FieldSelect *) expr)->resultcollid;
935 break;
936 case T_FieldStore:
937 /* FieldStore's result is composite ... */
938 coll = InvalidOid; /* ... so it has no collation */
939 break;
940 case T_RelabelType:
941 coll = ((const RelabelType *) expr)->resultcollid;
942 break;
943 case T_CoerceViaIO:
944 coll = ((const CoerceViaIO *) expr)->resultcollid;
945 break;
947 coll = ((const ArrayCoerceExpr *) expr)->resultcollid;
948 break;
950 /* ConvertRowtypeExpr's result is composite ... */
951 coll = InvalidOid; /* ... so it has no collation */
952 break;
953 case T_CollateExpr:
954 coll = ((const CollateExpr *) expr)->collOid;
955 break;
956 case T_CaseExpr:
957 coll = ((const CaseExpr *) expr)->casecollid;
958 break;
959 case T_CaseTestExpr:
960 coll = ((const CaseTestExpr *) expr)->collation;
961 break;
962 case T_ArrayExpr:
963 coll = ((const ArrayExpr *) expr)->array_collid;
964 break;
965 case T_RowExpr:
966 /* RowExpr's result is composite ... */
967 coll = InvalidOid; /* ... so it has no collation */
968 break;
969 case T_RowCompareExpr:
970 /* RowCompareExpr's result is boolean ... */
971 coll = InvalidOid; /* ... so it has no collation */
972 break;
973 case T_CoalesceExpr:
974 coll = ((const CoalesceExpr *) expr)->coalescecollid;
975 break;
976 case T_MinMaxExpr:
977 coll = ((const MinMaxExpr *) expr)->minmaxcollid;
978 break;
980 /* Returns either NAME or a non-collatable type */
981 if (((const SQLValueFunction *) expr)->type == NAMEOID)
983 else
985 break;
986 case T_XmlExpr:
987
988 /*
989 * XMLSERIALIZE returns text from non-collatable inputs, so its
990 * collation is always default. The other cases return boolean or
991 * XML, which are non-collatable.
992 */
993 if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
995 else
997 break;
998 case T_JsonValueExpr:
999 coll = exprCollation((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
1000 break;
1002 {
1003 const JsonConstructorExpr *ctor = (const JsonConstructorExpr *) expr;
1004
1005 /*
1006 * Collation comes from coercion if present, otherwise from
1007 * func. The func fallback is needed in cases where func
1008 * already produces the final output type and no coercion is
1009 * needed (cf. the JSCTOR_JSON_ARRAY_QUERY case).
1010 */
1011 if (ctor->coercion)
1012 coll = exprCollation((Node *) ctor->coercion);
1013 else if (ctor->func)
1014 coll = exprCollation((Node *) ctor->func);
1015 else
1016 coll = InvalidOid;
1017 }
1018 break;
1019 case T_JsonIsPredicate:
1020 /* IS JSON's result is boolean ... */
1021 coll = InvalidOid; /* ... so it has no collation */
1022 break;
1023 case T_JsonExpr:
1024 {
1025 const JsonExpr *jsexpr = (const JsonExpr *) expr;
1026
1027 coll = jsexpr->collation;
1028 }
1029 break;
1030 case T_JsonBehavior:
1031 {
1032 const JsonBehavior *behavior = (const JsonBehavior *) expr;
1033
1034 if (behavior->expr)
1035 coll = exprCollation(behavior->expr);
1036 else
1037 coll = InvalidOid;
1038 }
1039 break;
1040 case T_NullTest:
1041 /* NullTest's result is boolean ... */
1042 coll = InvalidOid; /* ... so it has no collation */
1043 break;
1044 case T_BooleanTest:
1045 /* BooleanTest's result is boolean ... */
1046 coll = InvalidOid; /* ... so it has no collation */
1047 break;
1048 case T_CoerceToDomain:
1049 coll = ((const CoerceToDomain *) expr)->resultcollid;
1050 break;
1052 coll = ((const CoerceToDomainValue *) expr)->collation;
1053 break;
1054 case T_SetToDefault:
1055 coll = ((const SetToDefault *) expr)->collation;
1056 break;
1057 case T_CurrentOfExpr:
1058 /* CurrentOfExpr's result is boolean ... */
1059 coll = InvalidOid; /* ... so it has no collation */
1060 break;
1061 case T_NextValueExpr:
1062 /* NextValueExpr's result is an integer type ... */
1063 coll = InvalidOid; /* ... so it has no collation */
1064 break;
1065 case T_InferenceElem:
1066 coll = exprCollation((Node *) ((const InferenceElem *) expr)->expr);
1067 break;
1068 case T_ReturningExpr:
1069 coll = exprCollation((Node *) ((const ReturningExpr *) expr)->retexpr);
1070 break;
1071 case T_PlaceHolderVar:
1072 coll = exprCollation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1073 break;
1074 case T_GraphPropertyRef:
1075 coll = ((const GraphPropertyRef *) expr)->collation;
1076 break;
1077 default:
1078 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1079 coll = InvalidOid; /* keep compiler quiet */
1080 break;
1081 }
1082 return coll;
1083}
#define Assert(condition)
Definition c.h:943
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
#define linitial_node(type, l)
Definition pg_list.h:181
#define linitial(l)
Definition pg_list.h:178
#define InvalidOid
@ ARRAY_SUBLINK
Definition primnodes.h:1036
@ EXPR_SUBLINK
Definition primnodes.h:1034
@ IS_XMLSERIALIZE
Definition primnodes.h:1613
Oid collation
Definition primnodes.h:1896
Oid firstColCollation
Definition primnodes.h:1109
SubLinkType subLinkType
Definition primnodes.h:1098
const char * type

References arg, ARRAY_SUBLINK, Assert, JsonExpr::collation, elog, ERROR, JsonBehavior::expr, EXPR_SUBLINK, exprCollation(), fb(), SubPlan::firstColCollation, InvalidOid, IS_XMLSERIALIZE, IsA, linitial, linitial_node, nodeTag, SubPlan::subLinkType, and type.

Referenced by addRangeTableEntryForFunction(), addRangeTableEntryForGraphTable(), addRangeTableEntryForGroup(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_collations_walker(), assign_hypothetical_collations(), build_expression_pathkey(), build_generation_expression(), build_pertrans_for_aggref(), build_subplan(), canonicalize_ec_expression(), check_simple_rowfilter_expr_walker(), coerce_type_typmod(), ComputeIndexAttrs(), ComputePartitionAttrs(), convert_EXISTS_to_ANY(), create_ctas_nodata(), create_grouping_expr_infos(), create_limit_plan(), create_memoize_plan(), create_windowagg_plan(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_attribute(), examine_expression(), ExecInitFunctionScan(), ExecInitIndexScan(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprCollation(), exprSetCollation(), extended_statistics_update(), extract_grouping_collations(), fix_indexqual_operand(), generate_query_for_empty_path_pattern(), generate_setop_tlist(), generate_subquery_params(), get_eclass_for_sortgroupclause(), get_expr_result_type(), get_first_col_type(), group_by_has_partkey(), have_partkey_equi_join(), init_grouping_targets(), inline_function(), insert_property_record(), make_pathkey_from_sortop(), make_recursive_union(), make_setop(), make_sort_from_groupcols(), make_sort_from_sortclauses(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), mcv_match_expression(), ordered_set_startup(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), preprocess_minmax_aggregates(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), replace_outer_returning(), scalararraysel(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), statatt_get_type(), tlist_same_collations(), transformCaseExpr(), transformFromClauseItem(), transformJsonArrayQueryConstructor(), transformJsonBehavior(), transformJsonTableColumns(), transformMultiAssignRef(), transformPLAssignStmtTarget(), transformSubLink(), and transformWindowDefinitions().

◆ expression_returns_set()

◆ expression_returns_set_walker()

static bool expression_returns_set_walker ( Node node,
void context 
)
static

Definition at line 774 of file nodeFuncs.c.

775{
776 if (node == NULL)
777 return false;
778 if (IsA(node, FuncExpr))
779 {
780 FuncExpr *expr = (FuncExpr *) node;
781
782 if (expr->funcretset)
783 return true;
784 /* else fall through to check args */
785 }
786 if (IsA(node, OpExpr))
787 {
788 OpExpr *expr = (OpExpr *) node;
789
790 if (expr->opretset)
791 return true;
792 /* else fall through to check args */
793 }
794
795 /*
796 * If you add any more cases that return sets, also fix
797 * expression_returns_set_rows() in clauses.c and IS_SRF_CALL() in
798 * tlist.c.
799 */
800
801 /* Avoid recursion for some cases that parser checks not to return a set */
802 if (IsA(node, Aggref))
803 return false;
804 if (IsA(node, GroupingFunc))
805 return false;
806 if (IsA(node, WindowFunc))
807 return false;
808
810 context);
811}
#define expression_tree_walker(n, w, c)
Definition nodeFuncs.h:153

References expression_returns_set_walker(), expression_tree_walker, fb(), and IsA.

Referenced by expression_returns_set(), and expression_returns_set_walker().

◆ expression_tree_mutator_impl()

Node * expression_tree_mutator_impl ( Node node,
tree_mutator_callback  mutator,
void context 
)

Definition at line 3015 of file nodeFuncs.c.

3018{
3019 /*
3020 * The mutator has already decided not to modify the current node, but we
3021 * must call the mutator for any sub-nodes.
3022 */
3023
3024#define FLATCOPY(newnode, node, nodetype) \
3025 ( (newnode) = palloc_object(nodetype), \
3026 memcpy((newnode), (node), sizeof(nodetype)) )
3027
3028#define MUTATE(newfield, oldfield, fieldtype) \
3029 ( (newfield) = (fieldtype) mutator((Node *) (oldfield), context) )
3030
3031 if (node == NULL)
3032 return NULL;
3033
3034 /* Guard against stack overflow due to overly complex expressions */
3036
3037 switch (nodeTag(node))
3038 {
3039 /*
3040 * Primitive node types with no expression subnodes. Var and
3041 * Const are frequent enough to deserve special cases, the others
3042 * we just use copyObject for.
3043 */
3044 case T_Var:
3045 {
3046 Var *var = (Var *) node;
3047 Var *newnode;
3048
3049 FLATCOPY(newnode, var, Var);
3050 /* Assume we need not copy the varnullingrels bitmapset */
3051 return (Node *) newnode;
3052 }
3053 break;
3054 case T_Const:
3055 {
3056 Const *oldnode = (Const *) node;
3057 Const *newnode;
3058
3060 /* XXX we don't bother with datumCopy; should we? */
3061 return (Node *) newnode;
3062 }
3063 break;
3064 case T_Param:
3065 case T_CaseTestExpr:
3066 case T_SQLValueFunction:
3067 case T_JsonFormat:
3069 case T_SetToDefault:
3070 case T_CurrentOfExpr:
3071 case T_NextValueExpr:
3072 case T_RangeTblRef:
3073 case T_SortGroupClause:
3074 case T_CTESearchClause:
3075 case T_MergeSupportFunc:
3076 return copyObject(node);
3077 case T_WithCheckOption:
3078 {
3081
3083 MUTATE(newnode->qual, wco->qual, Node *);
3084 return (Node *) newnode;
3085 }
3086 case T_Aggref:
3087 {
3088 Aggref *aggref = (Aggref *) node;
3089 Aggref *newnode;
3090
3091 FLATCOPY(newnode, aggref, Aggref);
3092 /* assume mutation doesn't change types of arguments */
3093 newnode->aggargtypes = list_copy(aggref->aggargtypes);
3094 MUTATE(newnode->aggdirectargs, aggref->aggdirectargs, List *);
3095 MUTATE(newnode->args, aggref->args, List *);
3096 MUTATE(newnode->aggorder, aggref->aggorder, List *);
3097 MUTATE(newnode->aggdistinct, aggref->aggdistinct, List *);
3098 MUTATE(newnode->aggfilter, aggref->aggfilter, Expr *);
3099 return (Node *) newnode;
3100 }
3101 break;
3102 case T_GroupingFunc:
3103 {
3106
3108 MUTATE(newnode->args, grouping->args, List *);
3109
3110 /*
3111 * We assume here that mutating the arguments does not change
3112 * the semantics, i.e. that the arguments are not mutated in a
3113 * way that makes them semantically different from their
3114 * previously matching expressions in the GROUP BY clause.
3115 *
3116 * If a mutator somehow wanted to do this, it would have to
3117 * handle the refs and cols lists itself as appropriate.
3118 */
3119 newnode->refs = list_copy(grouping->refs);
3120 newnode->cols = list_copy(grouping->cols);
3121
3122 return (Node *) newnode;
3123 }
3124 break;
3125 case T_WindowFunc:
3126 {
3127 WindowFunc *wfunc = (WindowFunc *) node;
3129
3130 FLATCOPY(newnode, wfunc, WindowFunc);
3131 MUTATE(newnode->args, wfunc->args, List *);
3132 MUTATE(newnode->aggfilter, wfunc->aggfilter, Expr *);
3133 return (Node *) newnode;
3134 }
3135 break;
3137 {
3140
3142 MUTATE(newnode->arg, wfuncrc->arg, Expr *);
3143 return (Node *) newnode;
3144 }
3145 break;
3146 case T_SubscriptingRef:
3147 {
3148 SubscriptingRef *sbsref = (SubscriptingRef *) node;
3150
3152 MUTATE(newnode->refupperindexpr, sbsref->refupperindexpr,
3153 List *);
3154 MUTATE(newnode->reflowerindexpr, sbsref->reflowerindexpr,
3155 List *);
3156 MUTATE(newnode->refexpr, sbsref->refexpr,
3157 Expr *);
3158 MUTATE(newnode->refassgnexpr, sbsref->refassgnexpr,
3159 Expr *);
3160
3161 return (Node *) newnode;
3162 }
3163 break;
3164 case T_FuncExpr:
3165 {
3166 FuncExpr *expr = (FuncExpr *) node;
3168
3169 FLATCOPY(newnode, expr, FuncExpr);
3170 MUTATE(newnode->args, expr->args, List *);
3171 return (Node *) newnode;
3172 }
3173 break;
3174 case T_NamedArgExpr:
3175 {
3176 NamedArgExpr *nexpr = (NamedArgExpr *) node;
3178
3180 MUTATE(newnode->arg, nexpr->arg, Expr *);
3181 return (Node *) newnode;
3182 }
3183 break;
3184 case T_OpExpr:
3185 {
3186 OpExpr *expr = (OpExpr *) node;
3187 OpExpr *newnode;
3188
3189 FLATCOPY(newnode, expr, OpExpr);
3190 MUTATE(newnode->args, expr->args, List *);
3191 return (Node *) newnode;
3192 }
3193 break;
3194 case T_DistinctExpr:
3195 {
3196 DistinctExpr *expr = (DistinctExpr *) node;
3198
3200 MUTATE(newnode->args, expr->args, List *);
3201 return (Node *) newnode;
3202 }
3203 break;
3204 case T_NullIfExpr:
3205 {
3206 NullIfExpr *expr = (NullIfExpr *) node;
3208
3209 FLATCOPY(newnode, expr, NullIfExpr);
3210 MUTATE(newnode->args, expr->args, List *);
3211 return (Node *) newnode;
3212 }
3213 break;
3215 {
3216 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
3218
3220 MUTATE(newnode->args, expr->args, List *);
3221 return (Node *) newnode;
3222 }
3223 break;
3224 case T_BoolExpr:
3225 {
3226 BoolExpr *expr = (BoolExpr *) node;
3228
3229 FLATCOPY(newnode, expr, BoolExpr);
3230 MUTATE(newnode->args, expr->args, List *);
3231 return (Node *) newnode;
3232 }
3233 break;
3234 case T_SubLink:
3235 {
3236 SubLink *sublink = (SubLink *) node;
3238
3240 MUTATE(newnode->testexpr, sublink->testexpr, Node *);
3241
3242 /*
3243 * Also invoke the mutator on the sublink's Query node, so it
3244 * can recurse into the sub-query if it wants to.
3245 */
3246 MUTATE(newnode->subselect, sublink->subselect, Node *);
3247 return (Node *) newnode;
3248 }
3249 break;
3250 case T_SubPlan:
3251 {
3252 SubPlan *subplan = (SubPlan *) node;
3254
3255 FLATCOPY(newnode, subplan, SubPlan);
3256 /* transform testexpr */
3257 MUTATE(newnode->testexpr, subplan->testexpr, Node *);
3258 /* transform args list (params to be passed to subplan) */
3259 MUTATE(newnode->args, subplan->args, List *);
3260 /* but not the sub-Plan itself, which is referenced as-is */
3261 return (Node *) newnode;
3262 }
3263 break;
3265 {
3268
3270 MUTATE(newnode->subplans, asplan->subplans, List *);
3271 return (Node *) newnode;
3272 }
3273 break;
3274 case T_FieldSelect:
3275 {
3276 FieldSelect *fselect = (FieldSelect *) node;
3278
3280 MUTATE(newnode->arg, fselect->arg, Expr *);
3281 return (Node *) newnode;
3282 }
3283 break;
3284 case T_FieldStore:
3285 {
3286 FieldStore *fstore = (FieldStore *) node;
3288
3289 FLATCOPY(newnode, fstore, FieldStore);
3290 MUTATE(newnode->arg, fstore->arg, Expr *);
3291 MUTATE(newnode->newvals, fstore->newvals, List *);
3292 newnode->fieldnums = list_copy(fstore->fieldnums);
3293 return (Node *) newnode;
3294 }
3295 break;
3296 case T_RelabelType:
3297 {
3298 RelabelType *relabel = (RelabelType *) node;
3300
3302 MUTATE(newnode->arg, relabel->arg, Expr *);
3303 return (Node *) newnode;
3304 }
3305 break;
3306 case T_CoerceViaIO:
3307 {
3308 CoerceViaIO *iocoerce = (CoerceViaIO *) node;
3310
3311 FLATCOPY(newnode, iocoerce, CoerceViaIO);
3312 MUTATE(newnode->arg, iocoerce->arg, Expr *);
3313 return (Node *) newnode;
3314 }
3315 break;
3316 case T_ArrayCoerceExpr:
3317 {
3320
3322 MUTATE(newnode->arg, acoerce->arg, Expr *);
3323 MUTATE(newnode->elemexpr, acoerce->elemexpr, Expr *);
3324 return (Node *) newnode;
3325 }
3326 break;
3328 {
3331
3333 MUTATE(newnode->arg, convexpr->arg, Expr *);
3334 return (Node *) newnode;
3335 }
3336 break;
3337 case T_CollateExpr:
3338 {
3339 CollateExpr *collate = (CollateExpr *) node;
3341
3342 FLATCOPY(newnode, collate, CollateExpr);
3343 MUTATE(newnode->arg, collate->arg, Expr *);
3344 return (Node *) newnode;
3345 }
3346 break;
3347 case T_CaseExpr:
3348 {
3349 CaseExpr *caseexpr = (CaseExpr *) node;
3351
3353 MUTATE(newnode->arg, caseexpr->arg, Expr *);
3354 MUTATE(newnode->args, caseexpr->args, List *);
3355 MUTATE(newnode->defresult, caseexpr->defresult, Expr *);
3356 return (Node *) newnode;
3357 }
3358 break;
3359 case T_CaseWhen:
3360 {
3361 CaseWhen *casewhen = (CaseWhen *) node;
3363
3365 MUTATE(newnode->expr, casewhen->expr, Expr *);
3366 MUTATE(newnode->result, casewhen->result, Expr *);
3367 return (Node *) newnode;
3368 }
3369 break;
3370 case T_ArrayExpr:
3371 {
3372 ArrayExpr *arrayexpr = (ArrayExpr *) node;
3374
3375 FLATCOPY(newnode, arrayexpr, ArrayExpr);
3376 MUTATE(newnode->elements, arrayexpr->elements, List *);
3377 return (Node *) newnode;
3378 }
3379 break;
3380 case T_RowExpr:
3381 {
3382 RowExpr *rowexpr = (RowExpr *) node;
3384
3385 FLATCOPY(newnode, rowexpr, RowExpr);
3386 MUTATE(newnode->args, rowexpr->args, List *);
3387 /* Assume colnames needn't be duplicated */
3388 return (Node *) newnode;
3389 }
3390 break;
3391 case T_RowCompareExpr:
3392 {
3395
3397 MUTATE(newnode->largs, rcexpr->largs, List *);
3398 MUTATE(newnode->rargs, rcexpr->rargs, List *);
3399 return (Node *) newnode;
3400 }
3401 break;
3402 case T_CoalesceExpr:
3403 {
3406
3408 MUTATE(newnode->args, coalesceexpr->args, List *);
3409 return (Node *) newnode;
3410 }
3411 break;
3412 case T_MinMaxExpr:
3413 {
3414 MinMaxExpr *minmaxexpr = (MinMaxExpr *) node;
3416
3418 MUTATE(newnode->args, minmaxexpr->args, List *);
3419 return (Node *) newnode;
3420 }
3421 break;
3422 case T_XmlExpr:
3423 {
3424 XmlExpr *xexpr = (XmlExpr *) node;
3426
3427 FLATCOPY(newnode, xexpr, XmlExpr);
3428 MUTATE(newnode->named_args, xexpr->named_args, List *);
3429 /* assume mutator does not care about arg_names */
3430 MUTATE(newnode->args, xexpr->args, List *);
3431 return (Node *) newnode;
3432 }
3433 break;
3434 case T_JsonReturning:
3435 {
3436 JsonReturning *jr = (JsonReturning *) node;
3438
3440 MUTATE(newnode->format, jr->format, JsonFormat *);
3441
3442 return (Node *) newnode;
3443 }
3444 case T_JsonValueExpr:
3445 {
3446 JsonValueExpr *jve = (JsonValueExpr *) node;
3448
3450 MUTATE(newnode->raw_expr, jve->raw_expr, Expr *);
3451 MUTATE(newnode->formatted_expr, jve->formatted_expr, Expr *);
3452 MUTATE(newnode->format, jve->format, JsonFormat *);
3453
3454 return (Node *) newnode;
3455 }
3457 {
3460
3462 MUTATE(newnode->args, jce->args, List *);
3463 MUTATE(newnode->func, jce->func, Expr *);
3464 MUTATE(newnode->coercion, jce->coercion, Expr *);
3465 MUTATE(newnode->returning, jce->returning, JsonReturning *);
3466
3467 return (Node *) newnode;
3468 }
3469 case T_JsonIsPredicate:
3470 {
3471 JsonIsPredicate *pred = (JsonIsPredicate *) node;
3473
3475 MUTATE(newnode->expr, pred->expr, Node *);
3476 MUTATE(newnode->format, pred->format, JsonFormat *);
3477
3478 return (Node *) newnode;
3479 }
3480 case T_JsonExpr:
3481 {
3482 JsonExpr *jexpr = (JsonExpr *) node;
3484
3486 MUTATE(newnode->formatted_expr, jexpr->formatted_expr, Node *);
3487 MUTATE(newnode->path_spec, jexpr->path_spec, Node *);
3488 MUTATE(newnode->passing_values, jexpr->passing_values, List *);
3489 /* assume mutator does not care about passing_names */
3490 MUTATE(newnode->on_empty, jexpr->on_empty, JsonBehavior *);
3491 MUTATE(newnode->on_error, jexpr->on_error, JsonBehavior *);
3492 return (Node *) newnode;
3493 }
3494 break;
3495 case T_JsonBehavior:
3496 {
3497 JsonBehavior *behavior = (JsonBehavior *) node;
3499
3500 FLATCOPY(newnode, behavior, JsonBehavior);
3501 MUTATE(newnode->expr, behavior->expr, Node *);
3502 return (Node *) newnode;
3503 }
3504 break;
3505 case T_NullTest:
3506 {
3507 NullTest *ntest = (NullTest *) node;
3509
3511 MUTATE(newnode->arg, ntest->arg, Expr *);
3512 return (Node *) newnode;
3513 }
3514 break;
3515 case T_BooleanTest:
3516 {
3517 BooleanTest *btest = (BooleanTest *) node;
3519
3521 MUTATE(newnode->arg, btest->arg, Expr *);
3522 return (Node *) newnode;
3523 }
3524 break;
3525 case T_CoerceToDomain:
3526 {
3529
3531 MUTATE(newnode->arg, ctest->arg, Expr *);
3532 return (Node *) newnode;
3533 }
3534 break;
3535 case T_ReturningExpr:
3536 {
3537 ReturningExpr *rexpr = (ReturningExpr *) node;
3539
3541 MUTATE(newnode->retexpr, rexpr->retexpr, Expr *);
3542 return (Node *) newnode;
3543 }
3544 break;
3545 case T_TargetEntry:
3546 {
3549
3551 MUTATE(newnode->expr, targetentry->expr, Expr *);
3552 return (Node *) newnode;
3553 }
3554 break;
3555 case T_Query:
3556 /* Do nothing with a sub-Query, per discussion above */
3557 return node;
3558 case T_WindowClause:
3559 {
3560 WindowClause *wc = (WindowClause *) node;
3562
3564 MUTATE(newnode->partitionClause, wc->partitionClause, List *);
3565 MUTATE(newnode->orderClause, wc->orderClause, List *);
3566 MUTATE(newnode->startOffset, wc->startOffset, Node *);
3567 MUTATE(newnode->endOffset, wc->endOffset, Node *);
3568 return (Node *) newnode;
3569 }
3570 break;
3571 case T_CTECycleClause:
3572 {
3573 CTECycleClause *cc = (CTECycleClause *) node;
3575
3577 MUTATE(newnode->cycle_mark_value, cc->cycle_mark_value, Node *);
3578 MUTATE(newnode->cycle_mark_default, cc->cycle_mark_default, Node *);
3579 return (Node *) newnode;
3580 }
3581 break;
3582 case T_CommonTableExpr:
3583 {
3584 CommonTableExpr *cte = (CommonTableExpr *) node;
3586
3588
3589 /*
3590 * Also invoke the mutator on the CTE's Query node, so it can
3591 * recurse into the sub-query if it wants to.
3592 */
3593 MUTATE(newnode->ctequery, cte->ctequery, Node *);
3594
3595 MUTATE(newnode->search_clause, cte->search_clause, CTESearchClause *);
3596 MUTATE(newnode->cycle_clause, cte->cycle_clause, CTECycleClause *);
3597
3598 return (Node *) newnode;
3599 }
3600 break;
3602 {
3605
3607 MUTATE(newnode->listdatums, pbs->listdatums, List *);
3608 MUTATE(newnode->lowerdatums, pbs->lowerdatums, List *);
3609 MUTATE(newnode->upperdatums, pbs->upperdatums, List *);
3610 return (Node *) newnode;
3611 }
3612 break;
3614 {
3617
3619 MUTATE(newnode->value, prd->value, Node *);
3620 return (Node *) newnode;
3621 }
3622 break;
3623 case T_List:
3624 {
3625 /*
3626 * We assume the mutator isn't interested in the list nodes
3627 * per se, so just invoke it on each list element. NOTE: this
3628 * would fail badly on a list with integer elements!
3629 */
3631 ListCell *temp;
3632
3633 resultlist = NIL;
3634 foreach(temp, (List *) node)
3635 {
3637 mutator((Node *) lfirst(temp),
3638 context));
3639 }
3640 return (Node *) resultlist;
3641 }
3642 break;
3643 case T_FromExpr:
3644 {
3645 FromExpr *from = (FromExpr *) node;
3647
3648 FLATCOPY(newnode, from, FromExpr);
3649 MUTATE(newnode->fromlist, from->fromlist, List *);
3650 MUTATE(newnode->quals, from->quals, Node *);
3651 return (Node *) newnode;
3652 }
3653 break;
3654 case T_OnConflictExpr:
3655 {
3656 OnConflictExpr *oc = (OnConflictExpr *) node;
3658
3660 MUTATE(newnode->arbiterElems, oc->arbiterElems, List *);
3661 MUTATE(newnode->arbiterWhere, oc->arbiterWhere, Node *);
3662 MUTATE(newnode->onConflictSet, oc->onConflictSet, List *);
3663 MUTATE(newnode->onConflictWhere, oc->onConflictWhere, Node *);
3664 MUTATE(newnode->exclRelTlist, oc->exclRelTlist, List *);
3665
3666 return (Node *) newnode;
3667 }
3668 break;
3669 case T_MergeAction:
3670 {
3671 MergeAction *action = (MergeAction *) node;
3673
3674 FLATCOPY(newnode, action, MergeAction);
3675 MUTATE(newnode->qual, action->qual, Node *);
3676 MUTATE(newnode->targetList, action->targetList, List *);
3677
3678 return (Node *) newnode;
3679 }
3680 break;
3681 case T_ForPortionOfExpr:
3682 {
3685
3687 MUTATE(newnode->rangeVar, fpo->rangeVar, Var *);
3688 MUTATE(newnode->targetFrom, fpo->targetFrom, Node *);
3689 MUTATE(newnode->targetTo, fpo->targetTo, Node *);
3690 MUTATE(newnode->targetRange, fpo->targetRange, Node *);
3691 MUTATE(newnode->overlapsExpr, fpo->overlapsExpr, Node *);
3692 MUTATE(newnode->rangeTargetList, fpo->rangeTargetList, List *);
3693
3694 return (Node *) newnode;
3695 }
3696 break;
3698 {
3701
3703 MUTATE(newnode->exprs, opstep->exprs, List *);
3704
3705 return (Node *) newnode;
3706 }
3707 break;
3709 /* no expression sub-nodes */
3710 return copyObject(node);
3711 case T_JoinExpr:
3712 {
3713 JoinExpr *join = (JoinExpr *) node;
3715
3716 FLATCOPY(newnode, join, JoinExpr);
3717 MUTATE(newnode->larg, join->larg, Node *);
3718 MUTATE(newnode->rarg, join->rarg, Node *);
3719 MUTATE(newnode->quals, join->quals, Node *);
3720 /* We do not mutate alias or using by default */
3721 return (Node *) newnode;
3722 }
3723 break;
3724 case T_SetOperationStmt:
3725 {
3726 SetOperationStmt *setop = (SetOperationStmt *) node;
3728
3730 MUTATE(newnode->larg, setop->larg, Node *);
3731 MUTATE(newnode->rarg, setop->rarg, Node *);
3732 /* We do not mutate groupClauses by default */
3733 return (Node *) newnode;
3734 }
3735 break;
3736 case T_IndexClause:
3737 {
3738 IndexClause *iclause = (IndexClause *) node;
3740
3742 MUTATE(newnode->rinfo, iclause->rinfo, RestrictInfo *);
3743 MUTATE(newnode->indexquals, iclause->indexquals, List *);
3744 return (Node *) newnode;
3745 }
3746 break;
3747 case T_PlaceHolderVar:
3748 {
3749 PlaceHolderVar *phv = (PlaceHolderVar *) node;
3751
3753 MUTATE(newnode->phexpr, phv->phexpr, Expr *);
3754 /* Assume we need not copy the relids bitmapsets */
3755 return (Node *) newnode;
3756 }
3757 break;
3758 case T_InferenceElem:
3759 {
3762
3764 MUTATE(newnode->expr, newnode->expr, Node *);
3765 return (Node *) newnode;
3766 }
3767 break;
3768 case T_AppendRelInfo:
3769 {
3772
3774 MUTATE(newnode->translated_vars, appinfo->translated_vars, List *);
3775 /* Assume nothing need be done with parent_colnos[] */
3776 return (Node *) newnode;
3777 }
3778 break;
3779 case T_PlaceHolderInfo:
3780 {
3783
3785 MUTATE(newnode->ph_var, phinfo->ph_var, PlaceHolderVar *);
3786 /* Assume we need not copy the relids bitmapsets */
3787 return (Node *) newnode;
3788 }
3789 break;
3790 case T_RangeTblFunction:
3791 {
3792 RangeTblFunction *rtfunc = (RangeTblFunction *) node;
3794
3796 MUTATE(newnode->funcexpr, rtfunc->funcexpr, Node *);
3797 /* Assume we need not copy the coldef info lists */
3798 return (Node *) newnode;
3799 }
3800 break;
3802 {
3805
3807 MUTATE(newnode->args, tsc->args, List *);
3808 MUTATE(newnode->repeatable, tsc->repeatable, Expr *);
3809 return (Node *) newnode;
3810 }
3811 break;
3812 case T_TableFunc:
3813 {
3814 TableFunc *tf = (TableFunc *) node;
3816
3818 MUTATE(newnode->ns_uris, tf->ns_uris, List *);
3819 MUTATE(newnode->docexpr, tf->docexpr, Node *);
3820 MUTATE(newnode->rowexpr, tf->rowexpr, Node *);
3821 MUTATE(newnode->colexprs, tf->colexprs, List *);
3822 MUTATE(newnode->coldefexprs, tf->coldefexprs, List *);
3823 MUTATE(newnode->colvalexprs, tf->colvalexprs, List *);
3824 MUTATE(newnode->passingvalexprs, tf->passingvalexprs, List *);
3825 return (Node *) newnode;
3826 }
3827 break;
3828 default:
3829 elog(ERROR, "unrecognized node type: %d",
3830 (int) nodeTag(node));
3831 break;
3832 }
3833 /* can't get here, but keep compiler happy */
3834 return NULL;
3835}
List * lappend(List *list, void *datum)
Definition list.c:339
List * list_copy(const List *oldlist)
Definition list.c:1573
#define FLATCOPY(newnode, node, nodetype)
#define MUTATE(newfield, oldfield, fieldtype)
#define lfirst(lc)
Definition pg_list.h:172
#define NIL
Definition pg_list.h:68
void check_stack_depth(void)
Definition stack_depth.c:95
List * aggdistinct
Definition primnodes.h:494
List * aggdirectargs
Definition primnodes.h:485
List * args
Definition primnodes.h:488
Expr * aggfilter
Definition primnodes.h:497
List * aggorder
Definition primnodes.h:491
List * args
Definition primnodes.h:973
Node * cycle_mark_default
Node * cycle_mark_value
List * newvals
Definition primnodes.h:1195
Expr * arg
Definition primnodes.h:1194
Node * quals
Definition primnodes.h:2397
List * fromlist
Definition primnodes.h:2396
List * args
Definition primnodes.h:801
Node * quals
Definition primnodes.h:2377
Node * larg
Definition primnodes.h:2370
Node * rarg
Definition primnodes.h:2371
JsonFormat * format
Definition primnodes.h:1775
Definition pg_list.h:54
List * args
Definition primnodes.h:869
List * args
Definition primnodes.h:1450
List * args
Definition primnodes.h:1125
Node * testexpr
Definition primnodes.h:1100
Expr * refassgnexpr
Definition primnodes.h:736
List * refupperindexpr
Definition primnodes.h:726
List * reflowerindexpr
Definition primnodes.h:732
Node * docexpr
Definition primnodes.h:121
Node * rowexpr
Definition primnodes.h:123
List * colexprs
Definition primnodes.h:133
Node * startOffset
List * partitionClause
Node * endOffset
List * orderClause
List * args
Definition primnodes.h:606
Expr * aggfilter
Definition primnodes.h:608
List * args
Definition primnodes.h:1635
List * named_args
Definition primnodes.h:1631

References Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, FieldStore::arg, CoerceViaIO::arg, CollateExpr::arg, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, RowExpr::args, XmlExpr::args, check_stack_depth(), TableFunc::colexprs, copyObject, CommonTableExpr::ctequery, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, TableFunc::docexpr, elog, WindowClause::endOffset, ERROR, JsonIsPredicate::expr, JsonBehavior::expr, fb(), FLATCOPY, JsonIsPredicate::format, FromExpr::fromlist, RangeTblFunction::funcexpr, lappend(), SetOperationStmt::larg, JoinExpr::larg, lfirst, list_copy(), MUTATE, XmlExpr::named_args, FieldStore::newvals, NIL, nodeTag, WindowClause::orderClause, WindowClause::partitionClause, JoinExpr::quals, FromExpr::quals, SetOperationStmt::rarg, JoinExpr::rarg, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, ReturningExpr::retexpr, TableFunc::rowexpr, WindowClause::startOffset, and SubPlan::testexpr.

◆ expression_tree_walker_impl()

bool expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void context 
)

Definition at line 2111 of file nodeFuncs.c.

2114{
2115 ListCell *temp;
2116
2117 /*
2118 * The walker has already visited the current node, and so we need only
2119 * recurse into any sub-nodes it has.
2120 *
2121 * We assume that the walker is not interested in List nodes per se, so
2122 * when we expect a List we just recurse directly to self without
2123 * bothering to call the walker.
2124 */
2125#define WALK(n) walker((Node *) (n), context)
2126
2127#define LIST_WALK(l) expression_tree_walker_impl((Node *) (l), walker, context)
2128
2129 if (node == NULL)
2130 return false;
2131
2132 /* Guard against stack overflow due to overly complex expressions */
2134
2135 switch (nodeTag(node))
2136 {
2137 case T_Var:
2138 case T_Const:
2139 case T_Param:
2140 case T_CaseTestExpr:
2141 case T_SQLValueFunction:
2143 case T_SetToDefault:
2144 case T_CurrentOfExpr:
2145 case T_NextValueExpr:
2146 case T_RangeTblRef:
2147 case T_SortGroupClause:
2148 case T_CTESearchClause:
2149 case T_GraphPropertyRef:
2150 case T_MergeSupportFunc:
2151 /* primitive node types with no expression subnodes */
2152 break;
2153 case T_WithCheckOption:
2154 return WALK(((WithCheckOption *) node)->qual);
2155 case T_Aggref:
2156 {
2157 Aggref *expr = (Aggref *) node;
2158
2159 /* recurse directly on Lists */
2160 if (LIST_WALK(expr->aggdirectargs))
2161 return true;
2162 if (LIST_WALK(expr->args))
2163 return true;
2164 if (LIST_WALK(expr->aggorder))
2165 return true;
2166 if (LIST_WALK(expr->aggdistinct))
2167 return true;
2168 if (WALK(expr->aggfilter))
2169 return true;
2170 }
2171 break;
2172 case T_GroupingFunc:
2173 {
2175
2176 if (LIST_WALK(grouping->args))
2177 return true;
2178 }
2179 break;
2180 case T_WindowFunc:
2181 {
2182 WindowFunc *expr = (WindowFunc *) node;
2183
2184 /* recurse directly on List */
2185 if (LIST_WALK(expr->args))
2186 return true;
2187 if (WALK(expr->aggfilter))
2188 return true;
2189 if (WALK(expr->runCondition))
2190 return true;
2191 }
2192 break;
2194 {
2196
2197 if (WALK(expr->arg))
2198 return true;
2199 }
2200 break;
2201 case T_SubscriptingRef:
2202 {
2203 SubscriptingRef *sbsref = (SubscriptingRef *) node;
2204
2205 /* recurse directly for upper/lower container index lists */
2206 if (LIST_WALK(sbsref->refupperindexpr))
2207 return true;
2208 if (LIST_WALK(sbsref->reflowerindexpr))
2209 return true;
2210 /* walker must see the refexpr and refassgnexpr, however */
2211 if (WALK(sbsref->refexpr))
2212 return true;
2213
2214 if (WALK(sbsref->refassgnexpr))
2215 return true;
2216 }
2217 break;
2218 case T_FuncExpr:
2219 {
2220 FuncExpr *expr = (FuncExpr *) node;
2221
2222 if (LIST_WALK(expr->args))
2223 return true;
2224 }
2225 break;
2226 case T_NamedArgExpr:
2227 return WALK(((NamedArgExpr *) node)->arg);
2228 case T_OpExpr:
2229 case T_DistinctExpr: /* struct-equivalent to OpExpr */
2230 case T_NullIfExpr: /* struct-equivalent to OpExpr */
2231 {
2232 OpExpr *expr = (OpExpr *) node;
2233
2234 if (LIST_WALK(expr->args))
2235 return true;
2236 }
2237 break;
2239 {
2240 ScalarArrayOpExpr *expr = (ScalarArrayOpExpr *) node;
2241
2242 if (LIST_WALK(expr->args))
2243 return true;
2244 }
2245 break;
2246 case T_BoolExpr:
2247 {
2248 BoolExpr *expr = (BoolExpr *) node;
2249
2250 if (LIST_WALK(expr->args))
2251 return true;
2252 }
2253 break;
2254 case T_SubLink:
2255 {
2256 SubLink *sublink = (SubLink *) node;
2257
2258 if (WALK(sublink->testexpr))
2259 return true;
2260
2261 /*
2262 * Also invoke the walker on the sublink's Query node, so it
2263 * can recurse into the sub-query if it wants to.
2264 */
2265 return WALK(sublink->subselect);
2266 }
2267 break;
2268 case T_SubPlan:
2269 {
2270 SubPlan *subplan = (SubPlan *) node;
2271
2272 /* recurse into the testexpr, but not into the Plan */
2273 if (WALK(subplan->testexpr))
2274 return true;
2275 /* also examine args list */
2276 if (LIST_WALK(subplan->args))
2277 return true;
2278 }
2279 break;
2281 return LIST_WALK(((AlternativeSubPlan *) node)->subplans);
2282 case T_FieldSelect:
2283 return WALK(((FieldSelect *) node)->arg);
2284 case T_FieldStore:
2285 {
2286 FieldStore *fstore = (FieldStore *) node;
2287
2288 if (WALK(fstore->arg))
2289 return true;
2290 if (WALK(fstore->newvals))
2291 return true;
2292 }
2293 break;
2294 case T_RelabelType:
2295 return WALK(((RelabelType *) node)->arg);
2296 case T_CoerceViaIO:
2297 return WALK(((CoerceViaIO *) node)->arg);
2298 case T_ArrayCoerceExpr:
2299 {
2301
2302 if (WALK(acoerce->arg))
2303 return true;
2304 if (WALK(acoerce->elemexpr))
2305 return true;
2306 }
2307 break;
2309 return WALK(((ConvertRowtypeExpr *) node)->arg);
2310 case T_CollateExpr:
2311 return WALK(((CollateExpr *) node)->arg);
2312 case T_CaseExpr:
2313 {
2314 CaseExpr *caseexpr = (CaseExpr *) node;
2315
2316 if (WALK(caseexpr->arg))
2317 return true;
2318 /* we assume walker doesn't care about CaseWhens, either */
2319 foreach(temp, caseexpr->args)
2320 {
2322
2323 if (WALK(when->expr))
2324 return true;
2325 if (WALK(when->result))
2326 return true;
2327 }
2328 if (WALK(caseexpr->defresult))
2329 return true;
2330 }
2331 break;
2332 case T_ArrayExpr:
2333 return WALK(((ArrayExpr *) node)->elements);
2334 case T_RowExpr:
2335 /* Assume colnames isn't interesting */
2336 return WALK(((RowExpr *) node)->args);
2337 case T_RowCompareExpr:
2338 {
2340
2341 if (WALK(rcexpr->largs))
2342 return true;
2343 if (WALK(rcexpr->rargs))
2344 return true;
2345 }
2346 break;
2347 case T_CoalesceExpr:
2348 return WALK(((CoalesceExpr *) node)->args);
2349 case T_MinMaxExpr:
2350 return WALK(((MinMaxExpr *) node)->args);
2351 case T_XmlExpr:
2352 {
2353 XmlExpr *xexpr = (XmlExpr *) node;
2354
2355 if (WALK(xexpr->named_args))
2356 return true;
2357 /* we assume walker doesn't care about arg_names */
2358 if (WALK(xexpr->args))
2359 return true;
2360 }
2361 break;
2362 case T_JsonValueExpr:
2363 {
2364 JsonValueExpr *jve = (JsonValueExpr *) node;
2365
2366 if (WALK(jve->raw_expr))
2367 return true;
2368 if (WALK(jve->formatted_expr))
2369 return true;
2370 }
2371 break;
2373 {
2375
2376 if (WALK(ctor->args))
2377 return true;
2378 if (WALK(ctor->func))
2379 return true;
2380 if (WALK(ctor->coercion))
2381 return true;
2382 }
2383 break;
2384 case T_JsonIsPredicate:
2385 return WALK(((JsonIsPredicate *) node)->expr);
2386 case T_JsonExpr:
2387 {
2388 JsonExpr *jexpr = (JsonExpr *) node;
2389
2390 if (WALK(jexpr->formatted_expr))
2391 return true;
2392 if (WALK(jexpr->path_spec))
2393 return true;
2394 if (WALK(jexpr->passing_values))
2395 return true;
2396 /* we assume walker doesn't care about passing_names */
2397 if (WALK(jexpr->on_empty))
2398 return true;
2399 if (WALK(jexpr->on_error))
2400 return true;
2401 }
2402 break;
2403 case T_JsonBehavior:
2404 {
2405 JsonBehavior *behavior = (JsonBehavior *) node;
2406
2407 if (WALK(behavior->expr))
2408 return true;
2409 }
2410 break;
2411 case T_NullTest:
2412 return WALK(((NullTest *) node)->arg);
2413 case T_BooleanTest:
2414 return WALK(((BooleanTest *) node)->arg);
2415 case T_CoerceToDomain:
2416 return WALK(((CoerceToDomain *) node)->arg);
2417 case T_TargetEntry:
2418 return WALK(((TargetEntry *) node)->expr);
2419 case T_Query:
2420 /* Do nothing with a sub-Query, per discussion above */
2421 break;
2422 case T_WindowClause:
2423 {
2424 WindowClause *wc = (WindowClause *) node;
2425
2426 if (WALK(wc->partitionClause))
2427 return true;
2428 if (WALK(wc->orderClause))
2429 return true;
2430 if (WALK(wc->startOffset))
2431 return true;
2432 if (WALK(wc->endOffset))
2433 return true;
2434 }
2435 break;
2436 case T_CTECycleClause:
2437 {
2438 CTECycleClause *cc = (CTECycleClause *) node;
2439
2440 if (WALK(cc->cycle_mark_value))
2441 return true;
2442 if (WALK(cc->cycle_mark_default))
2443 return true;
2444 }
2445 break;
2446 case T_CommonTableExpr:
2447 {
2448 CommonTableExpr *cte = (CommonTableExpr *) node;
2449
2450 /*
2451 * Invoke the walker on the CTE's Query node, so it can
2452 * recurse into the sub-query if it wants to.
2453 */
2454 if (WALK(cte->ctequery))
2455 return true;
2456
2457 if (WALK(cte->search_clause))
2458 return true;
2459 if (WALK(cte->cycle_clause))
2460 return true;
2461 }
2462 break;
2463 case T_JsonKeyValue:
2464 {
2465 JsonKeyValue *kv = (JsonKeyValue *) node;
2466
2467 if (WALK(kv->key))
2468 return true;
2469 if (WALK(kv->value))
2470 return true;
2471 }
2472 break;
2474 {
2476
2477 if (LIST_WALK(ctor->exprs))
2478 return true;
2479 }
2480 break;
2482 {
2484
2485 if (LIST_WALK(ctor->exprs))
2486 return true;
2487 }
2488 break;
2490 {
2492
2493 if (WALK(ctor->query))
2494 return true;
2495 }
2496 break;
2498 {
2500
2501 if (WALK(ctor->agg_filter))
2502 return true;
2503 if (WALK(ctor->agg_order))
2504 return true;
2505 if (WALK(ctor->over))
2506 return true;
2507 }
2508 break;
2509 case T_JsonObjectAgg:
2510 {
2511 JsonObjectAgg *ctor = (JsonObjectAgg *) node;
2512
2513 if (WALK(ctor->constructor))
2514 return true;
2515 if (WALK(ctor->arg))
2516 return true;
2517 }
2518 break;
2519 case T_JsonArrayAgg:
2520 {
2521 JsonArrayAgg *ctor = (JsonArrayAgg *) node;
2522
2523 if (WALK(ctor->constructor))
2524 return true;
2525 if (WALK(ctor->arg))
2526 return true;
2527 }
2528 break;
2529
2531 {
2533
2534 if (WALK(pbs->listdatums))
2535 return true;
2536 if (WALK(pbs->lowerdatums))
2537 return true;
2538 if (WALK(pbs->upperdatums))
2539 return true;
2540 }
2541 break;
2543 {
2545
2546 if (WALK(prd->value))
2547 return true;
2548 }
2549 break;
2550 case T_List:
2551 foreach(temp, (List *) node)
2552 {
2553 if (WALK(lfirst(temp)))
2554 return true;
2555 }
2556 break;
2557 case T_FromExpr:
2558 {
2559 FromExpr *from = (FromExpr *) node;
2560
2561 if (LIST_WALK(from->fromlist))
2562 return true;
2563 if (WALK(from->quals))
2564 return true;
2565 }
2566 break;
2567 case T_OnConflictExpr:
2568 {
2569 OnConflictExpr *onconflict = (OnConflictExpr *) node;
2570
2571 if (WALK(onconflict->arbiterElems))
2572 return true;
2573 if (WALK(onconflict->arbiterWhere))
2574 return true;
2575 if (WALK(onconflict->onConflictSet))
2576 return true;
2577 if (WALK(onconflict->onConflictWhere))
2578 return true;
2579 if (WALK(onconflict->exclRelTlist))
2580 return true;
2581 }
2582 break;
2583 case T_MergeAction:
2584 {
2585 MergeAction *action = (MergeAction *) node;
2586
2587 if (WALK(action->qual))
2588 return true;
2589 if (WALK(action->targetList))
2590 return true;
2591 }
2592 break;
2593 case T_ForPortionOfExpr:
2594 {
2595 ForPortionOfExpr *forPortionOf = (ForPortionOfExpr *) node;
2596
2597 if (WALK(forPortionOf->rangeVar))
2598 return true;
2599 if (WALK(forPortionOf->targetFrom))
2600 return true;
2601 if (WALK(forPortionOf->targetTo))
2602 return true;
2603 if (WALK(forPortionOf->targetRange))
2604 return true;
2605 if (WALK(forPortionOf->overlapsExpr))
2606 return true;
2607 if (WALK(forPortionOf->rangeTargetList))
2608 return true;
2609 }
2610 break;
2612 {
2614
2615 if (WALK(opstep->exprs))
2616 return true;
2617 }
2618 break;
2620 /* no expression subnodes */
2621 break;
2622 case T_JoinExpr:
2623 {
2624 JoinExpr *join = (JoinExpr *) node;
2625
2626 if (WALK(join->larg))
2627 return true;
2628 if (WALK(join->rarg))
2629 return true;
2630 if (WALK(join->quals))
2631 return true;
2632
2633 /*
2634 * alias clause, using list are deemed uninteresting.
2635 */
2636 }
2637 break;
2638 case T_SetOperationStmt:
2639 {
2640 SetOperationStmt *setop = (SetOperationStmt *) node;
2641
2642 if (WALK(setop->larg))
2643 return true;
2644 if (WALK(setop->rarg))
2645 return true;
2646
2647 /* groupClauses are deemed uninteresting */
2648 }
2649 break;
2650 case T_IndexClause:
2651 {
2652 IndexClause *iclause = (IndexClause *) node;
2653
2654 if (WALK(iclause->rinfo))
2655 return true;
2656 if (LIST_WALK(iclause->indexquals))
2657 return true;
2658 }
2659 break;
2660 case T_PlaceHolderVar:
2661 return WALK(((PlaceHolderVar *) node)->phexpr);
2662 case T_InferenceElem:
2663 return WALK(((InferenceElem *) node)->expr);
2664 case T_ReturningExpr:
2665 return WALK(((ReturningExpr *) node)->retexpr);
2666 case T_AppendRelInfo:
2667 {
2669
2670 if (LIST_WALK(appinfo->translated_vars))
2671 return true;
2672 }
2673 break;
2674 case T_PlaceHolderInfo:
2675 return WALK(((PlaceHolderInfo *) node)->ph_var);
2676 case T_RangeTblFunction:
2677 return WALK(((RangeTblFunction *) node)->funcexpr);
2679 {
2681
2682 if (LIST_WALK(tsc->args))
2683 return true;
2684 if (WALK(tsc->repeatable))
2685 return true;
2686 }
2687 break;
2688 case T_TableFunc:
2689 {
2690 TableFunc *tf = (TableFunc *) node;
2691
2692 if (WALK(tf->ns_uris))
2693 return true;
2694 if (WALK(tf->docexpr))
2695 return true;
2696 if (WALK(tf->rowexpr))
2697 return true;
2698 if (WALK(tf->colexprs))
2699 return true;
2700 if (WALK(tf->coldefexprs))
2701 return true;
2702 if (WALK(tf->colvalexprs))
2703 return true;
2704 if (WALK(tf->passingvalexprs))
2705 return true;
2706 }
2707 break;
2709 {
2711
2712 if (WALK(gep->subexpr))
2713 return true;
2714 if (WALK(gep->whereClause))
2715 return true;
2716 }
2717 break;
2718 case T_GraphPattern:
2719 {
2720 GraphPattern *gp = (GraphPattern *) node;
2721
2722 if (LIST_WALK(gp->path_pattern_list))
2723 return true;
2724 if (WALK(gp->whereClause))
2725 return true;
2726 }
2727 break;
2728 default:
2729 elog(ERROR, "unrecognized node type: %d",
2730 (int) nodeTag(node));
2731 break;
2732 }
2733 return false;
2734
2735 /* The WALK() macro can be re-used below, but LIST_WALK() not so much */
2736#undef LIST_WALK
2737}
#define LIST_WALK(l)
#define WALK(n)
#define lfirst_node(type, lc)
Definition pg_list.h:176
List * rangeTargetList
Definition primnodes.h:2460
List * arbiterElems
Definition primnodes.h:2415
List * onConflictSet
Definition primnodes.h:2424
List * exclRelTlist
Definition primnodes.h:2429
Node * onConflictWhere
Definition primnodes.h:2427
Node * arbiterWhere
Definition primnodes.h:2417
Definition type.h:89

References Aggref::aggdirectargs, Aggref::aggdistinct, Aggref::aggfilter, WindowFunc::aggfilter, Aggref::aggorder, OnConflictExpr::arbiterElems, OnConflictExpr::arbiterWhere, arg, WindowFuncRunCondition::arg, FieldStore::arg, Aggref::args, WindowFunc::args, FuncExpr::args, OpExpr::args, ScalarArrayOpExpr::args, BoolExpr::args, SubPlan::args, XmlExpr::args, check_stack_depth(), TableFunc::colexprs, CommonTableExpr::ctequery, CTECycleClause::cycle_mark_default, CTECycleClause::cycle_mark_value, TableFunc::docexpr, elog, WindowClause::endOffset, ERROR, OnConflictExpr::exclRelTlist, JsonBehavior::expr, fb(), FromExpr::fromlist, SetOperationStmt::larg, JoinExpr::larg, lfirst, lfirst_node, LIST_WALK, XmlExpr::named_args, FieldStore::newvals, nodeTag, OnConflictExpr::onConflictSet, OnConflictExpr::onConflictWhere, WindowClause::orderClause, ForPortionOfExpr::overlapsExpr, WindowClause::partitionClause, JoinExpr::quals, FromExpr::quals, ForPortionOfExpr::rangeTargetList, ForPortionOfExpr::rangeVar, SetOperationStmt::rarg, JoinExpr::rarg, SubscriptingRef::refassgnexpr, SubscriptingRef::refexpr, SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, TableFunc::rowexpr, WindowClause::startOffset, ForPortionOfExpr::targetFrom, ForPortionOfExpr::targetRange, ForPortionOfExpr::targetTo, SubPlan::testexpr, and WALK.

◆ exprInputCollation()

Oid exprInputCollation ( const Node expr)

Definition at line 1092 of file nodeFuncs.c.

1093{
1094 Oid coll;
1095
1096 if (!expr)
1097 return InvalidOid;
1098
1099 switch (nodeTag(expr))
1100 {
1101 case T_Aggref:
1102 coll = ((const Aggref *) expr)->inputcollid;
1103 break;
1104 case T_WindowFunc:
1105 coll = ((const WindowFunc *) expr)->inputcollid;
1106 break;
1107 case T_FuncExpr:
1108 coll = ((const FuncExpr *) expr)->inputcollid;
1109 break;
1110 case T_OpExpr:
1111 coll = ((const OpExpr *) expr)->inputcollid;
1112 break;
1113 case T_DistinctExpr:
1114 coll = ((const DistinctExpr *) expr)->inputcollid;
1115 break;
1116 case T_NullIfExpr:
1117 coll = ((const NullIfExpr *) expr)->inputcollid;
1118 break;
1120 coll = ((const ScalarArrayOpExpr *) expr)->inputcollid;
1121 break;
1122 case T_MinMaxExpr:
1123 coll = ((const MinMaxExpr *) expr)->inputcollid;
1124 break;
1125 default:
1126 coll = InvalidOid;
1127 break;
1128 }
1129 return coll;
1130}

References fb(), InvalidOid, and nodeTag.

Referenced by check_simple_rowfilter_expr_walker(), having_collation_conflict_walker(), and resolve_polymorphic_tupdesc().

◆ exprIsLengthCoercion()

bool exprIsLengthCoercion ( const Node expr,
int32 coercedTypmod 
)

Definition at line 562 of file nodeFuncs.c.

563{
564 if (coercedTypmod != NULL)
565 *coercedTypmod = -1; /* default result on failure */
566
567 /*
568 * Scalar-type length coercions are FuncExprs, array-type length coercions
569 * are ArrayCoerceExprs
570 */
571 if (expr && IsA(expr, FuncExpr))
572 {
573 const FuncExpr *func = (const FuncExpr *) expr;
574 int nargs;
576
577 /*
578 * If it didn't come from a coercion context, reject.
579 */
580 if (func->funcformat != COERCE_EXPLICIT_CAST &&
581 func->funcformat != COERCE_IMPLICIT_CAST)
582 return false;
583
584 /*
585 * If it's not a two-argument or three-argument function with the
586 * second argument being an int4 constant, it can't have been created
587 * from a length coercion (it must be a type coercion, instead).
588 */
589 nargs = list_length(func->args);
591 return false;
592
593 second_arg = (Const *) lsecond(func->args);
594 if (!IsA(second_arg, Const) ||
595 second_arg->consttype != INT4OID ||
596 second_arg->constisnull)
597 return false;
598
599 /*
600 * OK, it is indeed a length-coercion function.
601 */
602 if (coercedTypmod != NULL)
603 *coercedTypmod = DatumGetInt32(second_arg->constvalue);
604
605 return true;
606 }
607
608 if (expr && IsA(expr, ArrayCoerceExpr))
609 {
610 const ArrayCoerceExpr *acoerce = (const ArrayCoerceExpr *) expr;
611
612 /* It's not a length coercion unless there's a nondefault typmod */
613 if (acoerce->resulttypmod < 0)
614 return false;
615
616 /*
617 * OK, it is indeed a length-coercion expression.
618 */
619 if (coercedTypmod != NULL)
620 *coercedTypmod = acoerce->resulttypmod;
621
622 return true;
623 }
624
625 return false;
626}
static int list_length(const List *l)
Definition pg_list.h:152
#define lsecond(l)
Definition pg_list.h:183
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
@ COERCE_IMPLICIT_CAST
Definition primnodes.h:769
@ COERCE_EXPLICIT_CAST
Definition primnodes.h:768

References FuncExpr::args, COERCE_EXPLICIT_CAST, COERCE_IMPLICIT_CAST, DatumGetInt32(), fb(), IsA, list_length(), and lsecond.

Referenced by deparseFuncExpr(), exprTypmod(), and get_func_expr().

◆ exprLocation()

int exprLocation ( const Node expr)

Definition at line 1403 of file nodeFuncs.c.

1404{
1405 int loc;
1406
1407 if (expr == NULL)
1408 return -1;
1409 switch (nodeTag(expr))
1410 {
1411 case T_RangeVar:
1412 loc = ((const RangeVar *) expr)->location;
1413 break;
1414 case T_TableFunc:
1415 loc = ((const TableFunc *) expr)->location;
1416 break;
1417 case T_Var:
1418 loc = ((const Var *) expr)->location;
1419 break;
1420 case T_Const:
1421 loc = ((const Const *) expr)->location;
1422 break;
1423 case T_Param:
1424 loc = ((const Param *) expr)->location;
1425 break;
1426 case T_Aggref:
1427 /* function name should always be the first thing */
1428 loc = ((const Aggref *) expr)->location;
1429 break;
1430 case T_GroupingFunc:
1431 loc = ((const GroupingFunc *) expr)->location;
1432 break;
1433 case T_WindowFunc:
1434 /* function name should always be the first thing */
1435 loc = ((const WindowFunc *) expr)->location;
1436 break;
1437 case T_MergeSupportFunc:
1438 loc = ((const MergeSupportFunc *) expr)->location;
1439 break;
1440 case T_SubscriptingRef:
1441 /* just use container argument's location */
1442 loc = exprLocation((Node *) ((const SubscriptingRef *) expr)->refexpr);
1443 break;
1444 case T_FuncExpr:
1445 {
1446 const FuncExpr *fexpr = (const FuncExpr *) expr;
1447
1448 /* consider both function name and leftmost arg */
1449 loc = leftmostLoc(fexpr->location,
1450 exprLocation((Node *) fexpr->args));
1451 }
1452 break;
1453 case T_NamedArgExpr:
1454 {
1455 const NamedArgExpr *na = (const NamedArgExpr *) expr;
1456
1457 /* consider both argument name and value */
1458 loc = leftmostLoc(na->location,
1459 exprLocation((Node *) na->arg));
1460 }
1461 break;
1462 case T_OpExpr:
1463 case T_DistinctExpr: /* struct-equivalent to OpExpr */
1464 case T_NullIfExpr: /* struct-equivalent to OpExpr */
1465 {
1466 const OpExpr *opexpr = (const OpExpr *) expr;
1467
1468 /* consider both operator name and leftmost arg */
1469 loc = leftmostLoc(opexpr->location,
1470 exprLocation((Node *) opexpr->args));
1471 }
1472 break;
1474 {
1475 const ScalarArrayOpExpr *saopexpr = (const ScalarArrayOpExpr *) expr;
1476
1477 /* consider both operator name and leftmost arg */
1478 loc = leftmostLoc(saopexpr->location,
1479 exprLocation((Node *) saopexpr->args));
1480 }
1481 break;
1482 case T_BoolExpr:
1483 {
1484 const BoolExpr *bexpr = (const BoolExpr *) expr;
1485
1486 /*
1487 * Same as above, to handle either NOT or AND/OR. We can't
1488 * special-case NOT because of the way that it's used for
1489 * things like IS NOT BETWEEN.
1490 */
1491 loc = leftmostLoc(bexpr->location,
1492 exprLocation((Node *) bexpr->args));
1493 }
1494 break;
1495 case T_SubLink:
1496 {
1497 const SubLink *sublink = (const SubLink *) expr;
1498
1499 /* check the testexpr, if any, and the operator/keyword */
1500 loc = leftmostLoc(exprLocation(sublink->testexpr),
1501 sublink->location);
1502 }
1503 break;
1504 case T_FieldSelect:
1505 /* just use argument's location */
1506 loc = exprLocation((Node *) ((const FieldSelect *) expr)->arg);
1507 break;
1508 case T_FieldStore:
1509 /* just use argument's location */
1510 loc = exprLocation((Node *) ((const FieldStore *) expr)->arg);
1511 break;
1512 case T_RelabelType:
1513 {
1514 const RelabelType *rexpr = (const RelabelType *) expr;
1515
1516 /* Much as above */
1517 loc = leftmostLoc(rexpr->location,
1518 exprLocation((Node *) rexpr->arg));
1519 }
1520 break;
1521 case T_CoerceViaIO:
1522 {
1523 const CoerceViaIO *cexpr = (const CoerceViaIO *) expr;
1524
1525 /* Much as above */
1526 loc = leftmostLoc(cexpr->location,
1527 exprLocation((Node *) cexpr->arg));
1528 }
1529 break;
1530 case T_ArrayCoerceExpr:
1531 {
1532 const ArrayCoerceExpr *cexpr = (const ArrayCoerceExpr *) expr;
1533
1534 /* Much as above */
1535 loc = leftmostLoc(cexpr->location,
1536 exprLocation((Node *) cexpr->arg));
1537 }
1538 break;
1540 {
1541 const ConvertRowtypeExpr *cexpr = (const ConvertRowtypeExpr *) expr;
1542
1543 /* Much as above */
1544 loc = leftmostLoc(cexpr->location,
1545 exprLocation((Node *) cexpr->arg));
1546 }
1547 break;
1548 case T_CollateExpr:
1549 /* just use argument's location */
1550 loc = exprLocation((Node *) ((const CollateExpr *) expr)->arg);
1551 break;
1552 case T_CaseExpr:
1553 /* CASE keyword should always be the first thing */
1554 loc = ((const CaseExpr *) expr)->location;
1555 break;
1556 case T_CaseWhen:
1557 /* WHEN keyword should always be the first thing */
1558 loc = ((const CaseWhen *) expr)->location;
1559 break;
1560 case T_ArrayExpr:
1561 /* the location points at ARRAY or [, which must be leftmost */
1562 loc = ((const ArrayExpr *) expr)->location;
1563 break;
1564 case T_RowExpr:
1565 /* the location points at ROW or (, which must be leftmost */
1566 loc = ((const RowExpr *) expr)->location;
1567 break;
1568 case T_RowCompareExpr:
1569 /* just use leftmost argument's location */
1570 loc = exprLocation((Node *) ((const RowCompareExpr *) expr)->largs);
1571 break;
1572 case T_CoalesceExpr:
1573 /* COALESCE keyword should always be the first thing */
1574 loc = ((const CoalesceExpr *) expr)->location;
1575 break;
1576 case T_MinMaxExpr:
1577 /* GREATEST/LEAST keyword should always be the first thing */
1578 loc = ((const MinMaxExpr *) expr)->location;
1579 break;
1580 case T_SQLValueFunction:
1581 /* function keyword should always be the first thing */
1582 loc = ((const SQLValueFunction *) expr)->location;
1583 break;
1584 case T_XmlExpr:
1585 {
1586 const XmlExpr *xexpr = (const XmlExpr *) expr;
1587
1588 /* consider both function name and leftmost arg */
1589 loc = leftmostLoc(xexpr->location,
1590 exprLocation((Node *) xexpr->args));
1591 }
1592 break;
1593 case T_JsonFormat:
1594 loc = ((const JsonFormat *) expr)->location;
1595 break;
1596 case T_JsonValueExpr:
1597 loc = exprLocation((Node *) ((const JsonValueExpr *) expr)->raw_expr);
1598 break;
1600 loc = ((const JsonConstructorExpr *) expr)->location;
1601 break;
1602 case T_JsonIsPredicate:
1603 loc = ((const JsonIsPredicate *) expr)->location;
1604 break;
1605 case T_JsonExpr:
1606 {
1607 const JsonExpr *jsexpr = (const JsonExpr *) expr;
1608
1609 /* consider both function name and leftmost arg */
1610 loc = leftmostLoc(jsexpr->location,
1611 exprLocation(jsexpr->formatted_expr));
1612 }
1613 break;
1614 case T_JsonBehavior:
1615 loc = exprLocation(((const JsonBehavior *) expr)->expr);
1616 break;
1617 case T_NullTest:
1618 {
1619 const NullTest *nexpr = (const NullTest *) expr;
1620
1621 /* Much as above */
1622 loc = leftmostLoc(nexpr->location,
1623 exprLocation((Node *) nexpr->arg));
1624 }
1625 break;
1626 case T_BooleanTest:
1627 {
1628 const BooleanTest *bexpr = (const BooleanTest *) expr;
1629
1630 /* Much as above */
1631 loc = leftmostLoc(bexpr->location,
1632 exprLocation((Node *) bexpr->arg));
1633 }
1634 break;
1635 case T_CoerceToDomain:
1636 {
1637 const CoerceToDomain *cexpr = (const CoerceToDomain *) expr;
1638
1639 /* Much as above */
1640 loc = leftmostLoc(cexpr->location,
1641 exprLocation((Node *) cexpr->arg));
1642 }
1643 break;
1645 loc = ((const CoerceToDomainValue *) expr)->location;
1646 break;
1647 case T_SetToDefault:
1648 loc = ((const SetToDefault *) expr)->location;
1649 break;
1650 case T_ReturningExpr:
1651 loc = exprLocation((Node *) ((const ReturningExpr *) expr)->retexpr);
1652 break;
1653 case T_TargetEntry:
1654 /* just use argument's location */
1655 loc = exprLocation((Node *) ((const TargetEntry *) expr)->expr);
1656 break;
1657 case T_IntoClause:
1658 /* use the contained RangeVar's location --- close enough */
1659 loc = exprLocation((Node *) ((const IntoClause *) expr)->rel);
1660 break;
1661 case T_List:
1662 {
1663 /* report location of first list member that has a location */
1664 ListCell *lc;
1665
1666 loc = -1; /* just to suppress compiler warning */
1667 foreach(lc, (const List *) expr)
1668 {
1669 loc = exprLocation((Node *) lfirst(lc));
1670 if (loc >= 0)
1671 break;
1672 }
1673 }
1674 break;
1675 case T_A_Expr:
1676 {
1677 const A_Expr *aexpr = (const A_Expr *) expr;
1678
1679 /* use leftmost of operator or left operand (if any) */
1680 /* we assume right operand can't be to left of operator */
1681 loc = leftmostLoc(aexpr->location,
1682 exprLocation(aexpr->lexpr));
1683 }
1684 break;
1685 case T_ColumnRef:
1686 loc = ((const ColumnRef *) expr)->location;
1687 break;
1688 case T_ParamRef:
1689 loc = ((const ParamRef *) expr)->location;
1690 break;
1691 case T_A_Const:
1692 loc = ((const A_Const *) expr)->location;
1693 break;
1694 case T_FuncCall:
1695 {
1696 const FuncCall *fc = (const FuncCall *) expr;
1697
1698 /* consider both function name and leftmost arg */
1699 /* (we assume any ORDER BY nodes must be to right of name) */
1700 loc = leftmostLoc(fc->location,
1701 exprLocation((Node *) fc->args));
1702 }
1703 break;
1704 case T_A_ArrayExpr:
1705 /* the location points at ARRAY or [, which must be leftmost */
1706 loc = ((const A_ArrayExpr *) expr)->location;
1707 break;
1708 case T_ResTarget:
1709 /* we need not examine the contained expression (if any) */
1710 loc = ((const ResTarget *) expr)->location;
1711 break;
1712 case T_MultiAssignRef:
1713 loc = exprLocation(((const MultiAssignRef *) expr)->source);
1714 break;
1715 case T_TypeCast:
1716 {
1717 const TypeCast *tc = (const TypeCast *) expr;
1718
1719 /*
1720 * This could represent CAST(), ::, or TypeName 'literal', so
1721 * any of the components might be leftmost.
1722 */
1723 loc = exprLocation(tc->arg);
1724 loc = leftmostLoc(loc, tc->typeName->location);
1725 loc = leftmostLoc(loc, tc->location);
1726 }
1727 break;
1728 case T_CollateClause:
1729 /* just use argument's location */
1730 loc = exprLocation(((const CollateClause *) expr)->arg);
1731 break;
1732 case T_SortBy:
1733 /* just use argument's location (ignore operator, if any) */
1734 loc = exprLocation(((const SortBy *) expr)->node);
1735 break;
1736 case T_WindowDef:
1737 loc = ((const WindowDef *) expr)->location;
1738 break;
1739 case T_RangeTableSample:
1740 loc = ((const RangeTableSample *) expr)->location;
1741 break;
1742 case T_TypeName:
1743 loc = ((const TypeName *) expr)->location;
1744 break;
1745 case T_ColumnDef:
1746 loc = ((const ColumnDef *) expr)->location;
1747 break;
1748 case T_IndexElem:
1749 loc = ((const IndexElem *) expr)->location;
1750 break;
1751 case T_Constraint:
1752 loc = ((const Constraint *) expr)->location;
1753 break;
1755 loc = ((const FunctionParameter *) expr)->location;
1756 break;
1757 case T_XmlSerialize:
1758 /* XMLSERIALIZE keyword should always be the first thing */
1759 loc = ((const XmlSerialize *) expr)->location;
1760 break;
1761 case T_GroupingSet:
1762 loc = ((const GroupingSet *) expr)->location;
1763 break;
1764 case T_WithClause:
1765 loc = ((const WithClause *) expr)->location;
1766 break;
1767 case T_InferClause:
1768 loc = ((const InferClause *) expr)->location;
1769 break;
1770 case T_OnConflictClause:
1771 loc = ((const OnConflictClause *) expr)->location;
1772 break;
1773 case T_CTESearchClause:
1774 loc = ((const CTESearchClause *) expr)->location;
1775 break;
1776 case T_CTECycleClause:
1777 loc = ((const CTECycleClause *) expr)->location;
1778 break;
1779 case T_CommonTableExpr:
1780 loc = ((const CommonTableExpr *) expr)->location;
1781 break;
1782 case T_JsonKeyValue:
1783 /* just use the key's location */
1784 loc = exprLocation((Node *) ((const JsonKeyValue *) expr)->key);
1785 break;
1787 loc = ((const JsonObjectConstructor *) expr)->location;
1788 break;
1790 loc = ((const JsonArrayConstructor *) expr)->location;
1791 break;
1793 loc = ((const JsonArrayQueryConstructor *) expr)->location;
1794 break;
1796 loc = ((const JsonAggConstructor *) expr)->location;
1797 break;
1798 case T_JsonObjectAgg:
1799 loc = exprLocation((Node *) ((const JsonObjectAgg *) expr)->constructor);
1800 break;
1801 case T_JsonArrayAgg:
1802 loc = exprLocation((Node *) ((const JsonArrayAgg *) expr)->constructor);
1803 break;
1804 case T_PlaceHolderVar:
1805 /* just use argument's location */
1806 loc = exprLocation((Node *) ((const PlaceHolderVar *) expr)->phexpr);
1807 break;
1808 case T_InferenceElem:
1809 /* just use nested expr's location */
1810 loc = exprLocation((Node *) ((const InferenceElem *) expr)->expr);
1811 break;
1812 case T_PartitionElem:
1813 loc = ((const PartitionElem *) expr)->location;
1814 break;
1815 case T_PartitionSpec:
1816 loc = ((const PartitionSpec *) expr)->location;
1817 break;
1819 loc = ((const PartitionBoundSpec *) expr)->location;
1820 break;
1822 loc = ((const PartitionRangeDatum *) expr)->location;
1823 break;
1824 default:
1825 /* for any other node type it's just unknown... */
1826 loc = -1;
1827 break;
1828 }
1829 return loc;
1830}
static int leftmostLoc(int loc1, int loc2)
Definition nodeFuncs.c:1838
int exprLocation(const Node *expr)
Definition nodeFuncs.c:1403
static rewind_source * source
Definition pg_rewind.c:89
static int fc(const char *x)
ParseLoc location
Definition primnodes.h:1277
ParseLoc location
Definition primnodes.h:2076
ParseLoc location
Definition primnodes.h:1249
Node * formatted_expr
Definition primnodes.h:1863
ParseLoc location
Definition primnodes.h:1899
ParseLoc location
Definition primnodes.h:872
ParseLoc location
Definition primnodes.h:1227
ParseLoc location
Definition primnodes.h:1644

References arg, RelabelType::arg, CoerceViaIO::arg, ArrayCoerceExpr::arg, ConvertRowtypeExpr::arg, CoerceToDomain::arg, OpExpr::args, XmlExpr::args, exprLocation(), fb(), fc(), JsonExpr::formatted_expr, leftmostLoc(), lfirst, OpExpr::location, RelabelType::location, CoerceViaIO::location, ArrayCoerceExpr::location, ConvertRowtypeExpr::location, XmlExpr::location, JsonExpr::location, CoerceToDomain::location, nodeTag, and source.

Referenced by addRangeTableEntryForFunction(), addRangeTableEntryForTableFunc(), addTargetToSortList(), analyzeCTE(), array_subscript_transform(), assign_collations_walker(), check_agg_arguments_walker(), check_partition_bounds_for_split_list(), check_partition_bounds_for_split_range(), check_partitions_not_overlap_list(), check_simple_rowfilter_expr_walker(), check_srf_call_placement(), check_virtual_generated_security_walker(), checkWellFormedRecursion(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerceJsonFuncExpr(), constructSetOpTargetlist(), EvaluateParams(), ExecInitFunc(), ExecInitSubscriptingRef(), exprLocation(), finalize_grouping_exprs_walker(), generate_union_from_pathqueries(), get_matching_location(), hstore_subscript_transform(), init_sexpr(), jsonb_subscript_transform(), parseCheckAggregates(), ParseFuncOrColumn(), parser_coercion_errposition(), replace_outer_returning(), select_common_type(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformCaseExpr(), transformCoalesceExpr(), transformContainerSubscripts(), transformDistinctClause(), transformDistinctOnClause(), transformForPortionOfClause(), transformFrameOffset(), transformFromClauseItem(), transformGroupClause(), transformGroupClauseExpr(), transformGroupingSet(), transformIndirection(), transformInsertRow(), transformInsertStmt(), transformJsonBehavior(), transformJsonFuncExpr(), transformJsonIsPredicate(), transformJsonParseArg(), transformJsonValueExpr(), transformMultiAssignRef(), transformOnConflictArbiter(), transformPartitionBound(), transformPartitionBoundValue(), transformPartitionRangeBounds(), transformPLAssignStmtTarget(), transformRangeFunction(), transformReturningClause(), transformSelectStmt(), transformSetOperationStmt(), transformSetOperationTree(), transformValuesClause(), and validateInfiniteBounds().

◆ exprSetCollation()

void exprSetCollation ( Node expr,
Oid  collation 
)

Definition at line 1140 of file nodeFuncs.c.

1141{
1142 switch (nodeTag(expr))
1143 {
1144 case T_Var:
1145 ((Var *) expr)->varcollid = collation;
1146 break;
1147 case T_Const:
1148 ((Const *) expr)->constcollid = collation;
1149 break;
1150 case T_Param:
1151 ((Param *) expr)->paramcollid = collation;
1152 break;
1153 case T_Aggref:
1154 ((Aggref *) expr)->aggcollid = collation;
1155 break;
1156 case T_GroupingFunc:
1157 Assert(!OidIsValid(collation));
1158 break;
1159 case T_WindowFunc:
1160 ((WindowFunc *) expr)->wincollid = collation;
1161 break;
1162 case T_MergeSupportFunc:
1163 ((MergeSupportFunc *) expr)->msfcollid = collation;
1164 break;
1165 case T_SubscriptingRef:
1166 ((SubscriptingRef *) expr)->refcollid = collation;
1167 break;
1168 case T_FuncExpr:
1169 ((FuncExpr *) expr)->funccollid = collation;
1170 break;
1171 case T_NamedArgExpr:
1172 Assert(collation == exprCollation((Node *) ((NamedArgExpr *) expr)->arg));
1173 break;
1174 case T_OpExpr:
1175 ((OpExpr *) expr)->opcollid = collation;
1176 break;
1177 case T_DistinctExpr:
1178 ((DistinctExpr *) expr)->opcollid = collation;
1179 break;
1180 case T_NullIfExpr:
1181 ((NullIfExpr *) expr)->opcollid = collation;
1182 break;
1184 /* ScalarArrayOpExpr's result is boolean ... */
1185 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1186 break;
1187 case T_BoolExpr:
1188 /* BoolExpr's result is boolean ... */
1189 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1190 break;
1191 case T_SubLink:
1192#ifdef USE_ASSERT_CHECKING
1193 {
1194 SubLink *sublink = (SubLink *) expr;
1195
1196 if (sublink->subLinkType == EXPR_SUBLINK ||
1197 sublink->subLinkType == ARRAY_SUBLINK)
1198 {
1199 /* get the collation of subselect's first target column */
1200 Query *qtree = (Query *) sublink->subselect;
1202
1203 if (!qtree || !IsA(qtree, Query))
1204 elog(ERROR, "cannot set collation for untransformed sublink");
1205 tent = linitial_node(TargetEntry, qtree->targetList);
1206 Assert(!tent->resjunk);
1207 Assert(collation == exprCollation((Node *) tent->expr));
1208 }
1209 else
1210 {
1211 /* otherwise, result is RECORD or BOOLEAN */
1212 Assert(!OidIsValid(collation));
1213 }
1214 }
1215#endif /* USE_ASSERT_CHECKING */
1216 break;
1217 case T_FieldSelect:
1218 ((FieldSelect *) expr)->resultcollid = collation;
1219 break;
1220 case T_FieldStore:
1221 /* FieldStore's result is composite ... */
1222 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1223 break;
1224 case T_RelabelType:
1225 ((RelabelType *) expr)->resultcollid = collation;
1226 break;
1227 case T_CoerceViaIO:
1228 ((CoerceViaIO *) expr)->resultcollid = collation;
1229 break;
1230 case T_ArrayCoerceExpr:
1231 ((ArrayCoerceExpr *) expr)->resultcollid = collation;
1232 break;
1234 /* ConvertRowtypeExpr's result is composite ... */
1235 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1236 break;
1237 case T_CaseExpr:
1238 ((CaseExpr *) expr)->casecollid = collation;
1239 break;
1240 case T_ArrayExpr:
1241 ((ArrayExpr *) expr)->array_collid = collation;
1242 break;
1243 case T_RowExpr:
1244 /* RowExpr's result is composite ... */
1245 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1246 break;
1247 case T_RowCompareExpr:
1248 /* RowCompareExpr's result is boolean ... */
1249 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1250 break;
1251 case T_CoalesceExpr:
1252 ((CoalesceExpr *) expr)->coalescecollid = collation;
1253 break;
1254 case T_MinMaxExpr:
1255 ((MinMaxExpr *) expr)->minmaxcollid = collation;
1256 break;
1257 case T_SQLValueFunction:
1258 Assert((((SQLValueFunction *) expr)->type == NAMEOID) ?
1259 (collation == C_COLLATION_OID) :
1260 (collation == InvalidOid));
1261 break;
1262 case T_XmlExpr:
1263 Assert((((XmlExpr *) expr)->op == IS_XMLSERIALIZE) ?
1264 (collation == DEFAULT_COLLATION_OID) :
1265 (collation == InvalidOid));
1266 break;
1267 case T_JsonValueExpr:
1268 exprSetCollation((Node *) ((JsonValueExpr *) expr)->formatted_expr,
1269 collation);
1270 break;
1272 {
1274
1275 /* See comment in exprCollation() */
1276 if (ctor->coercion)
1277 exprSetCollation((Node *) ctor->coercion, collation);
1278 else if (ctor->func)
1279 exprSetCollation((Node *) ctor->func, collation);
1280 else
1281 Assert(!OidIsValid(collation)); /* result is always a
1282 * json[b] type */
1283 }
1284 break;
1285 case T_JsonIsPredicate:
1286 Assert(!OidIsValid(collation)); /* result is always boolean */
1287 break;
1288 case T_JsonExpr:
1289 {
1290 JsonExpr *jexpr = (JsonExpr *) expr;
1291
1292 jexpr->collation = collation;
1293 }
1294 break;
1295 case T_JsonBehavior:
1296 Assert(((JsonBehavior *) expr)->expr == NULL ||
1297 exprCollation(((JsonBehavior *) expr)->expr) == collation);
1298 break;
1299 case T_NullTest:
1300 /* NullTest's result is boolean ... */
1301 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1302 break;
1303 case T_BooleanTest:
1304 /* BooleanTest's result is boolean ... */
1305 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1306 break;
1307 case T_CoerceToDomain:
1308 ((CoerceToDomain *) expr)->resultcollid = collation;
1309 break;
1311 ((CoerceToDomainValue *) expr)->collation = collation;
1312 break;
1313 case T_SetToDefault:
1314 ((SetToDefault *) expr)->collation = collation;
1315 break;
1316 case T_CurrentOfExpr:
1317 /* CurrentOfExpr's result is boolean ... */
1318 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1319 break;
1320 case T_NextValueExpr:
1321 /* NextValueExpr's result is an integer type ... */
1322 Assert(!OidIsValid(collation)); /* ... so never set a collation */
1323 break;
1324 default:
1325 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
1326 break;
1327 }
1328}
#define OidIsValid(objectId)
Definition c.h:858
void exprSetCollation(Node *expr, Oid collation)
Definition nodeFuncs.c:1140

References arg, ARRAY_SUBLINK, Assert, elog, ERROR, EXPR_SUBLINK, exprCollation(), exprSetCollation(), fb(), InvalidOid, IS_XMLSERIALIZE, IsA, linitial_node, nodeTag, OidIsValid, and type.

Referenced by assign_collations_walker(), and exprSetCollation().

◆ exprSetInputCollation()

void exprSetInputCollation ( Node expr,
Oid  inputcollation 
)

Definition at line 1339 of file nodeFuncs.c.

1340{
1341 switch (nodeTag(expr))
1342 {
1343 case T_Aggref:
1344 ((Aggref *) expr)->inputcollid = inputcollation;
1345 break;
1346 case T_WindowFunc:
1347 ((WindowFunc *) expr)->inputcollid = inputcollation;
1348 break;
1349 case T_FuncExpr:
1350 ((FuncExpr *) expr)->inputcollid = inputcollation;
1351 break;
1352 case T_OpExpr:
1353 ((OpExpr *) expr)->inputcollid = inputcollation;
1354 break;
1355 case T_DistinctExpr:
1356 ((DistinctExpr *) expr)->inputcollid = inputcollation;
1357 break;
1358 case T_NullIfExpr:
1359 ((NullIfExpr *) expr)->inputcollid = inputcollation;
1360 break;
1362 ((ScalarArrayOpExpr *) expr)->inputcollid = inputcollation;
1363 break;
1364 case T_MinMaxExpr:
1365 ((MinMaxExpr *) expr)->inputcollid = inputcollation;
1366 break;
1367 default:
1368 break;
1369 }
1370}

References fb(), and nodeTag.

Referenced by assign_collations_walker().

◆ exprType()

Oid exprType ( const Node expr)

Definition at line 42 of file nodeFuncs.c.

43{
44 Oid type;
45
46 if (!expr)
47 return InvalidOid;
48
49 switch (nodeTag(expr))
50 {
51 case T_Var:
52 type = ((const Var *) expr)->vartype;
53 break;
54 case T_Const:
55 type = ((const Const *) expr)->consttype;
56 break;
57 case T_Param:
58 type = ((const Param *) expr)->paramtype;
59 break;
60 case T_Aggref:
61 type = ((const Aggref *) expr)->aggtype;
62 break;
63 case T_GroupingFunc:
64 type = INT4OID;
65 break;
66 case T_WindowFunc:
67 type = ((const WindowFunc *) expr)->wintype;
68 break;
70 type = ((const MergeSupportFunc *) expr)->msftype;
71 break;
73 type = ((const SubscriptingRef *) expr)->refrestype;
74 break;
75 case T_FuncExpr:
76 type = ((const FuncExpr *) expr)->funcresulttype;
77 break;
78 case T_NamedArgExpr:
79 type = exprType((Node *) ((const NamedArgExpr *) expr)->arg);
80 break;
81 case T_OpExpr:
82 type = ((const OpExpr *) expr)->opresulttype;
83 break;
84 case T_DistinctExpr:
85 type = ((const DistinctExpr *) expr)->opresulttype;
86 break;
87 case T_NullIfExpr:
88 type = ((const NullIfExpr *) expr)->opresulttype;
89 break;
91 type = BOOLOID;
92 break;
93 case T_BoolExpr:
94 type = BOOLOID;
95 break;
96 case T_SubLink:
97 {
98 const SubLink *sublink = (const SubLink *) expr;
99
100 if (sublink->subLinkType == EXPR_SUBLINK ||
101 sublink->subLinkType == ARRAY_SUBLINK)
102 {
103 /* get the type of the subselect's first target column */
104 Query *qtree = (Query *) sublink->subselect;
106
107 if (!qtree || !IsA(qtree, Query))
108 elog(ERROR, "cannot get type for untransformed sublink");
109 tent = linitial_node(TargetEntry, qtree->targetList);
110 Assert(!tent->resjunk);
111 type = exprType((Node *) tent->expr);
112 if (sublink->subLinkType == ARRAY_SUBLINK)
113 {
115 if (!OidIsValid(type))
118 errmsg("could not find array type for data type %s",
119 format_type_be(exprType((Node *) tent->expr)))));
120 }
121 }
122 else if (sublink->subLinkType == MULTIEXPR_SUBLINK)
123 {
124 /* MULTIEXPR is always considered to return RECORD */
125 type = RECORDOID;
126 }
127 else
128 {
129 /* for all other sublink types, result is boolean */
130 type = BOOLOID;
131 }
132 }
133 break;
134 case T_SubPlan:
135 {
136 const SubPlan *subplan = (const SubPlan *) expr;
137
138 if (subplan->subLinkType == EXPR_SUBLINK ||
139 subplan->subLinkType == ARRAY_SUBLINK)
140 {
141 /* get the type of the subselect's first target column */
142 type = subplan->firstColType;
143 if (subplan->subLinkType == ARRAY_SUBLINK)
144 {
146 if (!OidIsValid(type))
149 errmsg("could not find array type for data type %s",
150 format_type_be(subplan->firstColType))));
151 }
152 }
153 else if (subplan->subLinkType == MULTIEXPR_SUBLINK)
154 {
155 /* MULTIEXPR is always considered to return RECORD */
156 type = RECORDOID;
157 }
158 else
159 {
160 /* for all other subplan types, result is boolean */
161 type = BOOLOID;
162 }
163 }
164 break;
166 {
167 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
168
169 /* subplans should all return the same thing */
170 type = exprType((Node *) linitial(asplan->subplans));
171 }
172 break;
173 case T_FieldSelect:
174 type = ((const FieldSelect *) expr)->resulttype;
175 break;
176 case T_FieldStore:
177 type = ((const FieldStore *) expr)->resulttype;
178 break;
179 case T_RelabelType:
180 type = ((const RelabelType *) expr)->resulttype;
181 break;
182 case T_CoerceViaIO:
183 type = ((const CoerceViaIO *) expr)->resulttype;
184 break;
186 type = ((const ArrayCoerceExpr *) expr)->resulttype;
187 break;
189 type = ((const ConvertRowtypeExpr *) expr)->resulttype;
190 break;
191 case T_CollateExpr:
192 type = exprType((Node *) ((const CollateExpr *) expr)->arg);
193 break;
194 case T_CaseExpr:
195 type = ((const CaseExpr *) expr)->casetype;
196 break;
197 case T_CaseTestExpr:
198 type = ((const CaseTestExpr *) expr)->typeId;
199 break;
200 case T_ArrayExpr:
201 type = ((const ArrayExpr *) expr)->array_typeid;
202 break;
203 case T_RowExpr:
204 type = ((const RowExpr *) expr)->row_typeid;
205 break;
206 case T_RowCompareExpr:
207 type = BOOLOID;
208 break;
209 case T_CoalesceExpr:
210 type = ((const CoalesceExpr *) expr)->coalescetype;
211 break;
212 case T_MinMaxExpr:
213 type = ((const MinMaxExpr *) expr)->minmaxtype;
214 break;
216 type = ((const SQLValueFunction *) expr)->type;
217 break;
218 case T_XmlExpr:
219 if (((const XmlExpr *) expr)->op == IS_DOCUMENT)
220 type = BOOLOID;
221 else if (((const XmlExpr *) expr)->op == IS_XMLSERIALIZE)
222 type = TEXTOID;
223 else
224 type = XMLOID;
225 break;
226 case T_JsonValueExpr:
227 {
228 const JsonValueExpr *jve = (const JsonValueExpr *) expr;
229
230 type = exprType((Node *) jve->formatted_expr);
231 }
232 break;
234 type = ((const JsonConstructorExpr *) expr)->returning->typid;
235 break;
237 type = BOOLOID;
238 break;
239 case T_JsonExpr:
240 {
241 const JsonExpr *jexpr = (const JsonExpr *) expr;
242
244 break;
245 }
246 case T_JsonBehavior:
247 {
248 const JsonBehavior *behavior = (const JsonBehavior *) expr;
249
250 type = exprType(behavior->expr);
251 break;
252 }
253 case T_NullTest:
254 type = BOOLOID;
255 break;
256 case T_BooleanTest:
257 type = BOOLOID;
258 break;
259 case T_CoerceToDomain:
260 type = ((const CoerceToDomain *) expr)->resulttype;
261 break;
263 type = ((const CoerceToDomainValue *) expr)->typeId;
264 break;
265 case T_SetToDefault:
266 type = ((const SetToDefault *) expr)->typeId;
267 break;
268 case T_CurrentOfExpr:
269 type = BOOLOID;
270 break;
271 case T_NextValueExpr:
272 type = ((const NextValueExpr *) expr)->typeId;
273 break;
274 case T_InferenceElem:
275 {
276 const InferenceElem *n = (const InferenceElem *) expr;
277
278 type = exprType((Node *) n->expr);
279 }
280 break;
281 case T_ReturningExpr:
282 type = exprType((Node *) ((const ReturningExpr *) expr)->retexpr);
283 break;
284 case T_PlaceHolderVar:
285 type = exprType((Node *) ((const PlaceHolderVar *) expr)->phexpr);
286 break;
288 type = ((const GraphPropertyRef *) expr)->typeId;
289 break;
290 default:
291 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(expr));
292 type = InvalidOid; /* keep compiler quiet */
293 break;
294 }
295 return type;
296}
int errcode(int sqlerrcode)
Definition elog.c:875
#define ereport(elevel,...)
Definition elog.h:152
char * format_type_be(Oid type_oid)
Oid get_promoted_array_type(Oid typid)
Definition lsyscache.c:3006
static char * errmsg
@ MULTIEXPR_SUBLINK
Definition primnodes.h:1035
@ IS_DOCUMENT
Definition primnodes.h:1614
JsonReturning * returning
Definition primnodes.h:1872
Oid firstColType
Definition primnodes.h:1107

References arg, ARRAY_SUBLINK, Assert, elog, ereport, errcode(), errmsg, ERROR, JsonBehavior::expr, InferenceElem::expr, EXPR_SUBLINK, exprType(), fb(), SubPlan::firstColType, format_type_be(), get_promoted_array_type(), InvalidOid, IS_DOCUMENT, IS_XMLSERIALIZE, IsA, linitial, linitial_node, MULTIEXPR_SUBLINK, nodeTag, OidIsValid, SubPlan::subLinkType, and type.

Referenced by add_row_identity_var(), add_setop_child_rel_equivalences(), addRangeTableEntryForFunction(), addRangeTableEntryForGraphTable(), addRangeTableEntryForGroup(), addRangeTableEntryForSubquery(), addTargetToGroupList(), addTargetToSortList(), agg_args_support_sendreceive(), analyzeCTE(), analyzeCTETargetList(), appendAggOrderBy(), appendOrderByClause(), applyRelabelType(), array_subscript_transform(), assign_collations_walker(), assign_hypothetical_collations(), assign_param_for_placeholdervar(), ATExecAlterColumnType(), ATPrepAlterColumnType(), build_coercion_expression(), build_column_default(), build_edge_vertex_link_quals(), build_subplan(), calculate_frame_offsets(), CallStmtResultDesc(), can_minmax_aggs(), canonicalize_ec_expression(), check_functions_in_node(), check_hashjoinable(), check_memoizable(), check_mergejoinable(), check_simple_rowfilter_expr_walker(), check_sql_stmt_retval(), check_virtual_generated_security_walker(), checkRuleResultList(), coerce_fn_result_column(), coerce_record_to_complex(), coerce_to_boolean(), coerce_to_common_type(), coerce_to_specific_type_typmod(), coerceJsonFuncExpr(), compare_tlist_datatypes(), compute_semijoin_info(), ComputeIndexAttrs(), ComputePartitionAttrs(), constructSetOpTargetlist(), ConstructTupleDescriptor(), contain_mutable_functions_walker(), convert_EXISTS_to_ANY(), convert_VALUES_to_ANY(), cookDefault(), cost_qual_eval_walker(), create_ctas_nodata(), create_grouping_expr_infos(), create_indexscan_plan(), CreateStatistics(), DefineVirtualRelation(), deparseNullTest(), deparseOpExpr(), estimate_num_groups(), eval_const_expressions_mutator(), EvaluateParams(), examine_attribute(), examine_attribute(), examine_expression(), examine_variable(), exec_save_simple_expr(), ExecBuildProjectionInfo(), ExecBuildUpdateProjection(), ExecCheckPlanOutput(), ExecEvalXmlExpr(), ExecInitExprRec(), ExecInitIndexScan(), ExecInitJsonExpr(), ExecInitSubPlanExpr(), ExecMakeTableFunctionResult(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprType(), exprTypmod(), extended_statistics_update(), find_expr_references_walker(), find_placeholder_info(), fix_indexqual_operand(), foreign_expr_walker(), generate_append_tlist(), generate_join_implied_equalities_normal(), generate_query_for_empty_path_pattern(), generate_setop_child_grouplist(), generate_setop_tlist(), generate_subquery_params(), generateClonedIndexStmt(), get_call_expr_argtype(), get_expr_result_tupdesc(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_fn_expr_rettype(), get_func_expr(), get_oper_expr(), get_rule_expr(), get_rule_expr_funccall(), get_rule_orderby(), get_simple_binary_op_name(), get_sublink_expr(), get_windowfunc_expr_helper(), GetIndexInputType(), hash_ok_operator(), hstore_subscript_transform(), init_grouping_targets(), initialize_peragg(), inline_function(), insert_property_record(), internal_get_result_type(), jsonb_exec_setup(), jsonb_subscript_transform(), JsonTableInitOpaque(), jspIsMutableWalker(), make_op(), make_scalar_array_op(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), makeWholeRowVar(), match_orclause_to_indexcol(), match_pattern_prefix(), ordered_set_startup(), paraminfo_get_equal_hashops(), ParseFuncOrColumn(), pg_get_indexdef_worker(), pg_get_partkeydef_worker(), prepare_query_params(), preprocess_aggref(), preprocess_minmax_aggregates(), ProcedureCreate(), process_equivalence(), process_matched_tle(), recheck_cast_function_args(), relabel_to_typmod(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_grouping(), replace_outer_merge_support(), replace_outer_placeholdervar(), replace_outer_returning(), resolveTargetListUnknowns(), scalararraysel(), select_common_type(), select_common_typmod(), set_append_rel_size(), set_dummy_tlist_references(), set_joinrel_partition_key_exprs(), set_rel_width(), show_sortorder_options(), statatt_get_type(), tlist_same_datatypes(), transformAExprNullIf(), transformAggregateCall(), transformArrayExpr(), transformAssignedExpr(), transformAssignmentIndirection(), transformAssignmentSubscripts(), transformCaseExpr(), transformCollateClause(), transformExprRecurse(), transformForPortionOfClause(), transformFrameOffset(), transformFromClauseItem(), transformIndirection(), transformInsertStmt(), transformJsonArrayQueryConstructor(), transformJsonBehavior(), transformJsonConstructorOutput(), transformJsonFuncExpr(), transformJsonIsPredicate(), transformJsonParseArg(), transformJsonScalarExpr(), transformJsonTableColumns(), transformJsonValueExpr(), transformMultiAssignRef(), transformPartitionBoundValue(), transformPLAssignStmtTarget(), transformSubLink(), transformTypeCast(), unknown_attribute(), verify_common_type(), and xmlelement().

◆ exprTypmod()

int32 exprTypmod ( const Node expr)

Definition at line 304 of file nodeFuncs.c.

305{
306 if (!expr)
307 return -1;
308
309 switch (nodeTag(expr))
310 {
311 case T_Var:
312 return ((const Var *) expr)->vartypmod;
313 case T_Const:
314 return ((const Const *) expr)->consttypmod;
315 case T_Param:
316 return ((const Param *) expr)->paramtypmod;
318 return ((const SubscriptingRef *) expr)->reftypmod;
319 case T_FuncExpr:
320 {
322
323 /* Be smart about length-coercion functions... */
325 return coercedTypmod;
326 }
327 break;
328 case T_NamedArgExpr:
329 return exprTypmod((Node *) ((const NamedArgExpr *) expr)->arg);
330 case T_NullIfExpr:
331 {
332 /*
333 * Result is either first argument or NULL, so we can report
334 * first argument's typmod if known.
335 */
336 const NullIfExpr *nexpr = (const NullIfExpr *) expr;
337
338 return exprTypmod((Node *) linitial(nexpr->args));
339 }
340 break;
341 case T_SubLink:
342 {
343 const SubLink *sublink = (const SubLink *) expr;
344
345 if (sublink->subLinkType == EXPR_SUBLINK ||
346 sublink->subLinkType == ARRAY_SUBLINK)
347 {
348 /* get the typmod of the subselect's first target column */
349 Query *qtree = (Query *) sublink->subselect;
351
352 if (!qtree || !IsA(qtree, Query))
353 elog(ERROR, "cannot get type for untransformed sublink");
354 tent = linitial_node(TargetEntry, qtree->targetList);
355 Assert(!tent->resjunk);
356 return exprTypmod((Node *) tent->expr);
357 /* note we don't need to care if it's an array */
358 }
359 /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
360 }
361 break;
362 case T_SubPlan:
363 {
364 const SubPlan *subplan = (const SubPlan *) expr;
365
366 if (subplan->subLinkType == EXPR_SUBLINK ||
367 subplan->subLinkType == ARRAY_SUBLINK)
368 {
369 /* get the typmod of the subselect's first target column */
370 /* note we don't need to care if it's an array */
371 return subplan->firstColTypmod;
372 }
373 /* otherwise, result is RECORD or BOOLEAN, typmod is -1 */
374 }
375 break;
377 {
378 const AlternativeSubPlan *asplan = (const AlternativeSubPlan *) expr;
379
380 /* subplans should all return the same thing */
381 return exprTypmod((Node *) linitial(asplan->subplans));
382 }
383 break;
384 case T_FieldSelect:
385 return ((const FieldSelect *) expr)->resulttypmod;
386 case T_RelabelType:
387 return ((const RelabelType *) expr)->resulttypmod;
389 return ((const ArrayCoerceExpr *) expr)->resulttypmod;
390 case T_CollateExpr:
391 return exprTypmod((Node *) ((const CollateExpr *) expr)->arg);
392 case T_CaseExpr:
393 {
394 /*
395 * If all the alternatives agree on type/typmod, return that
396 * typmod, else use -1
397 */
398 const CaseExpr *cexpr = (const CaseExpr *) expr;
399 Oid casetype = cexpr->casetype;
400 int32 typmod;
401 ListCell *arg;
402
403 if (!cexpr->defresult)
404 return -1;
405 if (exprType((Node *) cexpr->defresult) != casetype)
406 return -1;
407 typmod = exprTypmod((Node *) cexpr->defresult);
408 if (typmod < 0)
409 return -1; /* no point in trying harder */
410 foreach(arg, cexpr->args)
411 {
413
414 if (exprType((Node *) w->result) != casetype)
415 return -1;
416 if (exprTypmod((Node *) w->result) != typmod)
417 return -1;
418 }
419 return typmod;
420 }
421 break;
422 case T_CaseTestExpr:
423 return ((const CaseTestExpr *) expr)->typeMod;
424 case T_ArrayExpr:
425 {
426 /*
427 * If all the elements agree on type/typmod, return that
428 * typmod, else use -1
429 */
430 const ArrayExpr *arrayexpr = (const ArrayExpr *) expr;
432 int32 typmod;
433 ListCell *elem;
434
435 if (arrayexpr->elements == NIL)
436 return -1;
437 typmod = exprTypmod((Node *) linitial(arrayexpr->elements));
438 if (typmod < 0)
439 return -1; /* no point in trying harder */
440 if (arrayexpr->multidims)
441 commontype = arrayexpr->array_typeid;
442 else
443 commontype = arrayexpr->element_typeid;
444 foreach(elem, arrayexpr->elements)
445 {
446 Node *e = (Node *) lfirst(elem);
447
448 if (exprType(e) != commontype)
449 return -1;
450 if (exprTypmod(e) != typmod)
451 return -1;
452 }
453 return typmod;
454 }
455 break;
456 case T_CoalesceExpr:
457 {
458 /*
459 * If all the alternatives agree on type/typmod, return that
460 * typmod, else use -1
461 */
462 const CoalesceExpr *cexpr = (const CoalesceExpr *) expr;
463 Oid coalescetype = cexpr->coalescetype;
464 int32 typmod;
465 ListCell *arg;
466
467 if (exprType((Node *) linitial(cexpr->args)) != coalescetype)
468 return -1;
469 typmod = exprTypmod((Node *) linitial(cexpr->args));
470 if (typmod < 0)
471 return -1; /* no point in trying harder */
472 for_each_from(arg, cexpr->args, 1)
473 {
474 Node *e = (Node *) lfirst(arg);
475
476 if (exprType(e) != coalescetype)
477 return -1;
478 if (exprTypmod(e) != typmod)
479 return -1;
480 }
481 return typmod;
482 }
483 break;
484 case T_MinMaxExpr:
485 {
486 /*
487 * If all the alternatives agree on type/typmod, return that
488 * typmod, else use -1
489 */
490 const MinMaxExpr *mexpr = (const MinMaxExpr *) expr;
491 Oid minmaxtype = mexpr->minmaxtype;
492 int32 typmod;
493 ListCell *arg;
494
495 if (exprType((Node *) linitial(mexpr->args)) != minmaxtype)
496 return -1;
497 typmod = exprTypmod((Node *) linitial(mexpr->args));
498 if (typmod < 0)
499 return -1; /* no point in trying harder */
500 for_each_from(arg, mexpr->args, 1)
501 {
502 Node *e = (Node *) lfirst(arg);
503
504 if (exprType(e) != minmaxtype)
505 return -1;
506 if (exprTypmod(e) != typmod)
507 return -1;
508 }
509 return typmod;
510 }
511 break;
513 return ((const SQLValueFunction *) expr)->typmod;
514 case T_JsonValueExpr:
515 return exprTypmod((Node *) ((const JsonValueExpr *) expr)->formatted_expr);
517 return ((const JsonConstructorExpr *) expr)->returning->typmod;
518 case T_JsonExpr:
519 {
520 const JsonExpr *jexpr = (const JsonExpr *) expr;
521
522 return jexpr->returning->typmod;
523 }
524 break;
525 case T_JsonBehavior:
526 {
527 const JsonBehavior *behavior = (const JsonBehavior *) expr;
528
529 return exprTypmod(behavior->expr);
530 }
531 break;
532 case T_CoerceToDomain:
533 return ((const CoerceToDomain *) expr)->resulttypmod;
535 return ((const CoerceToDomainValue *) expr)->typeMod;
536 case T_SetToDefault:
537 return ((const SetToDefault *) expr)->typeMod;
538 case T_ReturningExpr:
539 return exprTypmod((Node *) ((const ReturningExpr *) expr)->retexpr);
540 case T_PlaceHolderVar:
541 return exprTypmod((Node *) ((const PlaceHolderVar *) expr)->phexpr);
543 return ((const GraphPropertyRef *) expr)->typmod;
544 default:
545 break;
546 }
547 return -1;
548}
int32_t int32
Definition c.h:620
bool exprIsLengthCoercion(const Node *expr, int32 *coercedTypmod)
Definition nodeFuncs.c:562
#define for_each_from(cell, lst, N)
Definition pg_list.h:446
e
Expr * defresult
Definition primnodes.h:1350
List * args
Definition primnodes.h:1349
Expr * result
Definition primnodes.h:1361
int32 firstColTypmod
Definition primnodes.h:1108

References arg, CaseExpr::args, CoalesceExpr::args, ARRAY_SUBLINK, Assert, CaseExpr::defresult, elog, ERROR, JsonBehavior::expr, EXPR_SUBLINK, exprIsLengthCoercion(), exprType(), exprTypmod(), fb(), SubPlan::firstColTypmod, for_each_from, IsA, lfirst, lfirst_node, linitial, linitial_node, NIL, nodeTag, CaseWhen::result, and SubPlan::subLinkType.

Referenced by add_row_identity_var(), addRangeTableEntryForFunction(), addRangeTableEntryForGraphTable(), addRangeTableEntryForGroup(), addRangeTableEntryForSubquery(), analyzeCTE(), analyzeCTETargetList(), applyRelabelType(), assign_hypothetical_collations(), build_coercion_expression(), build_subplan(), canonicalize_ec_expression(), checkRuleResultList(), coerce_type_typmod(), ConstructTupleDescriptor(), convert_EXISTS_to_ANY(), create_ctas_nodata(), DefineVirtualRelation(), eval_const_expressions_mutator(), examine_attribute(), examine_attribute(), examine_expression(), examine_variable(), exec_save_simple_expr(), ExecInitJsonExpr(), ExecTypeFromExprList(), ExecTypeFromTLInternal(), expandRecordVariable(), expandRTE(), exprTypmod(), extended_statistics_update(), find_placeholder_info(), generate_append_tlist(), generate_query_for_empty_path_pattern(), generate_setop_tlist(), generate_subquery_params(), get_expr_result_type(), get_expr_width(), get_first_col_type(), get_rule_expr(), get_rule_expr_funccall(), insert_property_record(), interval_support(), JsonTableInitOpaque(), makeJsonConstructorExpr(), makeVarFromTargetEntry(), numeric_support(), preprocess_aggref(), RelationBuildPartitionKey(), RelationGetDummyIndexExpressions(), remove_unused_subquery_outputs(), replace_nestloop_param_placeholdervar(), replace_outer_placeholdervar(), replace_outer_returning(), select_common_typmod(), set_append_rel_size(), set_dummy_tlist_references(), set_rel_width(), statatt_get_type(), TemporalSimplify(), transformCaseExpr(), transformFromClauseItem(), transformIndirection(), transformInsertStmt(), transformJsonTableColumns(), transformMultiAssignRef(), transformPLAssignStmtTarget(), transformSubLink(), varbit_support(), and varchar_support().

◆ fix_opfuncids()

void fix_opfuncids ( Node node)

Definition at line 1859 of file nodeFuncs.c.

1860{
1861 /* This tree walk requires no special setup, so away we go... */
1863}
static bool fix_opfuncids_walker(Node *node, void *context)
Definition nodeFuncs.c:1866

References fb(), and fix_opfuncids_walker().

Referenced by evaluate_expr(), expression_planner(), expression_planner_with_deps(), extended_statistics_update(), fetch_statentries_for_relation(), get_qual_for_range(), get_relation_statistics(), operator_predicate_proof(), RelationBuildPartitionKey(), RelationGetIndexExpressions(), and RelationGetIndexPredicate().

◆ fix_opfuncids_walker()

static bool fix_opfuncids_walker ( Node node,
void context 
)
static

Definition at line 1866 of file nodeFuncs.c.

1867{
1868 if (node == NULL)
1869 return false;
1870 if (IsA(node, OpExpr))
1871 set_opfuncid((OpExpr *) node);
1872 else if (IsA(node, DistinctExpr))
1873 set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1874 else if (IsA(node, NullIfExpr))
1875 set_opfuncid((OpExpr *) node); /* rely on struct equivalence */
1876 else if (IsA(node, ScalarArrayOpExpr))
1878 return expression_tree_walker(node, fix_opfuncids_walker, context);
1879}

References expression_tree_walker, fb(), fix_opfuncids_walker(), IsA, set_opfuncid(), and set_sa_opfuncid().

Referenced by fix_opfuncids(), and fix_opfuncids_walker().

◆ leftmostLoc()

static int leftmostLoc ( int  loc1,
int  loc2 
)
static

Definition at line 1838 of file nodeFuncs.c.

1839{
1840 if (loc1 < 0)
1841 return loc2;
1842 else if (loc2 < 0)
1843 return loc1;
1844 else
1845 return Min(loc1, loc2);
1846}
#define Min(x, y)
Definition c.h:1091

References fb(), and Min.

Referenced by exprLocation().

◆ planstate_tree_walker_impl()

bool planstate_tree_walker_impl ( PlanState planstate,
planstate_tree_walker_callback  walker,
void context 
)

Definition at line 4841 of file nodeFuncs.c.

4844{
4845 Plan *plan = planstate->plan;
4846 ListCell *lc;
4847
4848 /* We don't need implicit coercions to Node here */
4849#define PSWALK(n) walker(n, context)
4850
4851 /* Guard against stack overflow due to overly complex plan trees */
4853
4854 /* initPlan-s */
4855 if (planstate_walk_subplans(planstate->initPlan, walker, context))
4856 return true;
4857
4858 /* lefttree */
4859 if (outerPlanState(planstate))
4860 {
4861 if (PSWALK(outerPlanState(planstate)))
4862 return true;
4863 }
4864
4865 /* righttree */
4866 if (innerPlanState(planstate))
4867 {
4868 if (PSWALK(innerPlanState(planstate)))
4869 return true;
4870 }
4871
4872 /* special child plans */
4873 switch (nodeTag(plan))
4874 {
4875 case T_Append:
4876 if (planstate_walk_members(((AppendState *) planstate)->appendplans,
4877 ((AppendState *) planstate)->as_nplans,
4878 walker, context))
4879 return true;
4880 break;
4881 case T_MergeAppend:
4882 if (planstate_walk_members(((MergeAppendState *) planstate)->mergeplans,
4883 ((MergeAppendState *) planstate)->ms_nplans,
4884 walker, context))
4885 return true;
4886 break;
4887 case T_BitmapAnd:
4888 if (planstate_walk_members(((BitmapAndState *) planstate)->bitmapplans,
4889 ((BitmapAndState *) planstate)->nplans,
4890 walker, context))
4891 return true;
4892 break;
4893 case T_BitmapOr:
4894 if (planstate_walk_members(((BitmapOrState *) planstate)->bitmapplans,
4895 ((BitmapOrState *) planstate)->nplans,
4896 walker, context))
4897 return true;
4898 break;
4899 case T_SubqueryScan:
4900 if (PSWALK(((SubqueryScanState *) planstate)->subplan))
4901 return true;
4902 break;
4903 case T_CustomScan:
4904 foreach(lc, ((CustomScanState *) planstate)->custom_ps)
4905 {
4906 if (PSWALK(lfirst(lc)))
4907 return true;
4908 }
4909 break;
4910 default:
4911 break;
4912 }
4913
4914 /* subPlan-s */
4915 if (planstate_walk_subplans(planstate->subPlan, walker, context))
4916 return true;
4917
4918 return false;
4919}
#define outerPlanState(node)
Definition execnodes.h:1299
#define innerPlanState(node)
Definition execnodes.h:1298
static bool planstate_walk_subplans(List *plans, planstate_tree_walker_callback walker, void *context)
Definition nodeFuncs.c:4925
#define PSWALK(n)
static bool planstate_walk_members(PlanState **planstates, int nplans, planstate_tree_walker_callback walker, void *context)
Definition nodeFuncs.c:4947
#define plan(x)
Definition pg_regress.c:164
Plan * plan
Definition execnodes.h:1201
List * initPlan
Definition execnodes.h:1228

References check_stack_depth(), fb(), PlanState::initPlan, innerPlanState, lfirst, nodeTag, outerPlanState, PlanState::plan, plan, planstate_walk_members(), planstate_walk_subplans(), PSWALK, and PlanState::subPlan.

◆ planstate_walk_members()

static bool planstate_walk_members ( PlanState **  planstates,
int  nplans,
planstate_tree_walker_callback  walker,
void context 
)
static

Definition at line 4947 of file nodeFuncs.c.

4950{
4951 for (int j = 0; j < nplans; j++)
4952 {
4953 if (PSWALK(planstates[j]))
4954 return true;
4955 }
4956
4957 return false;
4958}
int j
Definition isn.c:78

References fb(), j, and PSWALK.

Referenced by planstate_tree_walker_impl().

◆ planstate_walk_subplans()

static bool planstate_walk_subplans ( List plans,
planstate_tree_walker_callback  walker,
void context 
)
static

Definition at line 4925 of file nodeFuncs.c.

4928{
4929 ListCell *lc;
4930
4931 foreach(lc, plans)
4932 {
4934
4935 if (PSWALK(sps->planstate))
4936 return true;
4937 }
4938
4939 return false;
4940}

References fb(), lfirst_node, and PSWALK.

Referenced by planstate_tree_walker_impl().

◆ query_or_expression_tree_mutator_impl()

Node * query_or_expression_tree_mutator_impl ( Node node,
tree_mutator_callback  mutator,
void context,
int  flags 
)

Definition at line 4055 of file nodeFuncs.c.

4059{
4060 if (node && IsA(node, Query))
4061 return (Node *) query_tree_mutator((Query *) node,
4062 mutator,
4063 context,
4064 flags);
4065 else
4066 return mutator(node, context);
4067}
#define query_tree_mutator(q, m, c, f)
Definition nodeFuncs.h:160

References fb(), IsA, and query_tree_mutator.

◆ query_or_expression_tree_walker_impl()

bool query_or_expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void context,
int  flags 
)

Definition at line 4032 of file nodeFuncs.c.

4036{
4037 if (node && IsA(node, Query))
4038 return query_tree_walker((Query *) node,
4039 walker,
4040 context,
4041 flags);
4042 else
4043 return WALK(node);
4044}
#define query_tree_walker(q, w, c, f)
Definition nodeFuncs.h:158

References fb(), IsA, query_tree_walker, and WALK.

◆ query_tree_mutator_impl()

Query * query_tree_mutator_impl ( Query query,
tree_mutator_callback  mutator,
void context,
int  flags 
)

Definition at line 3858 of file nodeFuncs.c.

3862{
3863 Assert(query != NULL && IsA(query, Query));
3864
3865 if (!(flags & QTW_DONT_COPY_QUERY))
3866 {
3867 Query *newquery;
3868
3869 FLATCOPY(newquery, query, Query);
3870 query = newquery;
3871 }
3872
3873 MUTATE(query->targetList, query->targetList, List *);
3874 MUTATE(query->withCheckOptions, query->withCheckOptions, List *);
3875 MUTATE(query->onConflict, query->onConflict, OnConflictExpr *);
3876 MUTATE(query->mergeActionList, query->mergeActionList, List *);
3879 MUTATE(query->returningList, query->returningList, List *);
3880 MUTATE(query->jointree, query->jointree, FromExpr *);
3881 MUTATE(query->setOperations, query->setOperations, Node *);
3882 MUTATE(query->havingQual, query->havingQual, Node *);
3883 MUTATE(query->limitOffset, query->limitOffset, Node *);
3884 MUTATE(query->limitCount, query->limitCount, Node *);
3885
3886 /*
3887 * Most callers aren't interested in SortGroupClause nodes since those
3888 * don't contain actual expressions. However they do contain OIDs, which
3889 * may be of interest to some mutators.
3890 */
3891
3892 if ((flags & QTW_EXAMINE_SORTGROUP))
3893 {
3894 MUTATE(query->groupClause, query->groupClause, List *);
3895 MUTATE(query->windowClause, query->windowClause, List *);
3896 MUTATE(query->sortClause, query->sortClause, List *);
3897 MUTATE(query->distinctClause, query->distinctClause, List *);
3898 }
3899 else
3900 {
3901 /*
3902 * But we need to mutate the expressions under WindowClause nodes even
3903 * if we're not interested in SortGroupClause nodes.
3904 */
3906 ListCell *temp;
3907
3908 resultlist = NIL;
3909 foreach(temp, query->windowClause)
3910 {
3913
3915 MUTATE(newnode->startOffset, wc->startOffset, Node *);
3916 MUTATE(newnode->endOffset, wc->endOffset, Node *);
3917
3919 }
3920 query->windowClause = resultlist;
3921 }
3922
3923 /*
3924 * groupingSets and rowMarks are not mutated:
3925 *
3926 * groupingSets contain only ressortgroup refs (integers) which are
3927 * meaningless without the groupClause or tlist. Accordingly, any mutator
3928 * that needs to care about them needs to handle them itself in its Query
3929 * processing.
3930 *
3931 * rowMarks contains only rangetable indexes (and flags etc.) and
3932 * therefore should be handled at Query level similarly.
3933 */
3934
3935 if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
3936 MUTATE(query->cteList, query->cteList, List *);
3937 else /* else copy CTE list as-is */
3938 query->cteList = copyObject(query->cteList);
3939 query->rtable = range_table_mutator(query->rtable,
3940 mutator, context, flags);
3941 return query;
3942}
#define QTW_DONT_COPY_QUERY
Definition nodeFuncs.h:29
#define QTW_IGNORE_CTE_SUBQUERIES
Definition nodeFuncs.h:23
#define QTW_EXAMINE_SORTGROUP
Definition nodeFuncs.h:30
#define range_table_mutator(rt, m, c, f)
Definition nodeFuncs.h:165
Node * mergeJoinCondition
Definition parsenodes.h:199
Node * limitCount
Definition parsenodes.h:234
FromExpr * jointree
Definition parsenodes.h:185
List * returningList
Definition parsenodes.h:217
Node * setOperations
Definition parsenodes.h:239
List * cteList
Definition parsenodes.h:176
OnConflictExpr * onConflict
Definition parsenodes.h:206
ForPortionOfExpr * forPortionOf
Definition parsenodes.h:151
List * groupClause
Definition parsenodes.h:219
Node * havingQual
Definition parsenodes.h:225
List * rtable
Definition parsenodes.h:178
Node * limitOffset
Definition parsenodes.h:233
List * mergeActionList
Definition parsenodes.h:188
List * windowClause
Definition parsenodes.h:227
List * targetList
Definition parsenodes.h:201
List * distinctClause
Definition parsenodes.h:229
List * sortClause
Definition parsenodes.h:231

References Assert, copyObject, Query::cteList, Query::distinctClause, WindowClause::endOffset, fb(), FLATCOPY, Query::forPortionOf, Query::groupClause, Query::havingQual, IsA, Query::jointree, lappend(), lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, Query::mergeJoinCondition, MUTATE, NIL, Query::onConflict, QTW_DONT_COPY_QUERY, QTW_EXAMINE_SORTGROUP, QTW_IGNORE_CTE_SUBQUERIES, range_table_mutator, Query::returningList, Query::rtable, Query::setOperations, Query::sortClause, WindowClause::startOffset, Query::targetList, and Query::windowClause.

◆ query_tree_walker_impl()

bool query_tree_walker_impl ( Query query,
tree_walker_callback  walker,
void context,
int  flags 
)

Definition at line 2755 of file nodeFuncs.c.

2759{
2760 Assert(query != NULL && IsA(query, Query));
2761
2762 /*
2763 * We don't walk any utilityStmt here. However, we can't easily assert
2764 * that it is absent, since there are at least two code paths by which
2765 * action statements from CREATE RULE end up here, and NOTIFY is allowed
2766 * in a rule action.
2767 */
2768
2769 if (WALK(query->targetList))
2770 return true;
2771 if (WALK(query->withCheckOptions))
2772 return true;
2773 if (WALK(query->onConflict))
2774 return true;
2775 if (WALK(query->mergeActionList))
2776 return true;
2777 if (WALK(query->mergeJoinCondition))
2778 return true;
2779 if (WALK(query->forPortionOf))
2780 return true;
2781 if (WALK(query->returningList))
2782 return true;
2783 if (WALK(query->jointree))
2784 return true;
2785 if (WALK(query->setOperations))
2786 return true;
2787 if (WALK(query->havingQual))
2788 return true;
2789 if (WALK(query->limitOffset))
2790 return true;
2791 if (WALK(query->limitCount))
2792 return true;
2793
2794 /*
2795 * Most callers aren't interested in SortGroupClause nodes since those
2796 * don't contain actual expressions. However they do contain OIDs which
2797 * may be needed by dependency walkers etc.
2798 */
2799 if ((flags & QTW_EXAMINE_SORTGROUP))
2800 {
2801 if (WALK(query->groupClause))
2802 return true;
2803 if (WALK(query->windowClause))
2804 return true;
2805 if (WALK(query->sortClause))
2806 return true;
2807 if (WALK(query->distinctClause))
2808 return true;
2809 }
2810 else
2811 {
2812 /*
2813 * But we need to walk the expressions under WindowClause nodes even
2814 * if we're not interested in SortGroupClause nodes.
2815 */
2816 ListCell *lc;
2817
2818 foreach(lc, query->windowClause)
2819 {
2821
2822 if (WALK(wc->startOffset))
2823 return true;
2824 if (WALK(wc->endOffset))
2825 return true;
2826 }
2827 }
2828
2829 /*
2830 * groupingSets and rowMarks are not walked:
2831 *
2832 * groupingSets contain only ressortgrouprefs (integers) which are
2833 * meaningless without the corresponding groupClause or tlist.
2834 * Accordingly, any walker that needs to care about them needs to handle
2835 * them itself in its Query processing.
2836 *
2837 * rowMarks is not walked because it contains only rangetable indexes (and
2838 * flags etc.) and therefore should be handled at Query level similarly.
2839 */
2840
2841 if (!(flags & QTW_IGNORE_CTE_SUBQUERIES))
2842 {
2843 if (WALK(query->cteList))
2844 return true;
2845 }
2846 if (!(flags & QTW_IGNORE_RANGE_TABLE))
2847 {
2848 if (range_table_walker(query->rtable, walker, context, flags))
2849 return true;
2850 }
2851 return false;
2852}
#define range_table_walker(rt, w, c, f)
Definition nodeFuncs.h:163
#define QTW_IGNORE_RANGE_TABLE
Definition nodeFuncs.h:26

References Assert, Query::cteList, Query::distinctClause, WindowClause::endOffset, fb(), Query::forPortionOf, Query::groupClause, Query::havingQual, IsA, Query::jointree, lfirst_node, Query::limitCount, Query::limitOffset, Query::mergeActionList, Query::mergeJoinCondition, Query::onConflict, QTW_EXAMINE_SORTGROUP, QTW_IGNORE_CTE_SUBQUERIES, QTW_IGNORE_RANGE_TABLE, range_table_walker, Query::returningList, Query::rtable, Query::setOperations, Query::sortClause, WindowClause::startOffset, Query::targetList, WALK, and Query::windowClause.

◆ range_table_entry_walker_impl()

bool range_table_entry_walker_impl ( RangeTblEntry rte,
tree_walker_callback  walker,
void context,
int  flags 
)

Definition at line 2881 of file nodeFuncs.c.

2885{
2886 /*
2887 * Walkers might need to examine the RTE node itself either before or
2888 * after visiting its contents (or, conceivably, both). Note that if you
2889 * specify neither flag, the walker won't be called on the RTE at all.
2890 */
2891 if (flags & QTW_EXAMINE_RTES_BEFORE)
2892 if (WALK(rte))
2893 return true;
2894
2895 switch (rte->rtekind)
2896 {
2897 case RTE_RELATION:
2898 if (WALK(rte->tablesample))
2899 return true;
2900 break;
2901 case RTE_SUBQUERY:
2902 if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
2903 if (WALK(rte->subquery))
2904 return true;
2905 break;
2906 case RTE_JOIN:
2907 if (!(flags & QTW_IGNORE_JOINALIASES))
2908 if (WALK(rte->joinaliasvars))
2909 return true;
2910 break;
2911 case RTE_FUNCTION:
2912 if (WALK(rte->functions))
2913 return true;
2914 break;
2915 case RTE_TABLEFUNC:
2916 if (WALK(rte->tablefunc))
2917 return true;
2918 break;
2919 case RTE_VALUES:
2920 if (WALK(rte->values_lists))
2921 return true;
2922 break;
2923 case RTE_GRAPH_TABLE:
2924 if (WALK(rte->graph_pattern))
2925 return true;
2926 if (WALK(rte->graph_table_columns))
2927 return true;
2928 break;
2929 case RTE_CTE:
2931 case RTE_RESULT:
2932 /* nothing to do */
2933 break;
2934 case RTE_GROUP:
2935 if (!(flags & QTW_IGNORE_GROUPEXPRS))
2936 if (WALK(rte->groupexprs))
2937 return true;
2938 break;
2939 }
2940
2941 if (WALK(rte->securityQuals))
2942 return true;
2943
2944 if (flags & QTW_EXAMINE_RTES_AFTER)
2945 if (WALK(rte))
2946 return true;
2947
2948 return false;
2949}
#define QTW_IGNORE_RT_SUBQUERIES
Definition nodeFuncs.h:22
#define QTW_EXAMINE_RTES_AFTER
Definition nodeFuncs.h:28
#define QTW_IGNORE_GROUPEXPRS
Definition nodeFuncs.h:32
#define QTW_EXAMINE_RTES_BEFORE
Definition nodeFuncs.h:27
#define QTW_IGNORE_JOINALIASES
Definition nodeFuncs.h:25
@ RTE_JOIN
@ RTE_CTE
@ RTE_NAMEDTUPLESTORE
@ RTE_VALUES
@ RTE_SUBQUERY
@ RTE_RESULT
@ RTE_FUNCTION
@ RTE_TABLEFUNC
@ RTE_GROUP
@ RTE_GRAPH_TABLE
@ RTE_RELATION

References fb(), QTW_EXAMINE_RTES_AFTER, QTW_EXAMINE_RTES_BEFORE, QTW_IGNORE_GROUPEXPRS, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_GRAPH_TABLE, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, RTE_VALUES, and WALK.

◆ range_table_mutator_impl()

List * range_table_mutator_impl ( List rtable,
tree_mutator_callback  mutator,
void context,
int  flags 
)

Definition at line 3950 of file nodeFuncs.c.

3954{
3955 List *newrt = NIL;
3956 ListCell *rt;
3957
3958 foreach(rt, rtable)
3959 {
3962
3964 switch (rte->rtekind)
3965 {
3966 case RTE_RELATION:
3967 MUTATE(newrte->tablesample, rte->tablesample,
3969 /* we don't bother to copy eref, aliases, etc; OK? */
3970 break;
3971 case RTE_SUBQUERY:
3972 if (!(flags & QTW_IGNORE_RT_SUBQUERIES))
3973 MUTATE(newrte->subquery, rte->subquery, Query *);
3974 else
3975 {
3976 /* else, copy RT subqueries as-is */
3977 newrte->subquery = copyObject(rte->subquery);
3978 }
3979 break;
3980 case RTE_JOIN:
3981 if (!(flags & QTW_IGNORE_JOINALIASES))
3982 MUTATE(newrte->joinaliasvars, rte->joinaliasvars, List *);
3983 else
3984 {
3985 /* else, copy join aliases as-is */
3986 newrte->joinaliasvars = copyObject(rte->joinaliasvars);
3987 }
3988 break;
3989 case RTE_FUNCTION:
3990 MUTATE(newrte->functions, rte->functions, List *);
3991 break;
3992 case RTE_TABLEFUNC:
3993 MUTATE(newrte->tablefunc, rte->tablefunc, TableFunc *);
3994 break;
3995 case RTE_VALUES:
3996 MUTATE(newrte->values_lists, rte->values_lists, List *);
3997 break;
3998 case RTE_GRAPH_TABLE:
3999 MUTATE(newrte->graph_pattern, rte->graph_pattern, GraphPattern *);
4000 MUTATE(newrte->graph_table_columns, rte->graph_table_columns, List *);
4001 break;
4002 case RTE_CTE:
4004 case RTE_RESULT:
4005 /* nothing to do */
4006 break;
4007 case RTE_GROUP:
4008 if (!(flags & QTW_IGNORE_GROUPEXPRS))
4009 MUTATE(newrte->groupexprs, rte->groupexprs, List *);
4010 else
4011 {
4012 /* else, copy grouping exprs as-is */
4013 newrte->groupexprs = copyObject(rte->groupexprs);
4014 }
4015 break;
4016 }
4017 MUTATE(newrte->securityQuals, rte->securityQuals, List *);
4019 }
4020 return newrt;
4021}

References copyObject, fb(), FLATCOPY, lappend(), lfirst, MUTATE, NIL, QTW_IGNORE_GROUPEXPRS, QTW_IGNORE_JOINALIASES, QTW_IGNORE_RT_SUBQUERIES, RTE_CTE, RTE_FUNCTION, RTE_GRAPH_TABLE, RTE_GROUP, RTE_JOIN, RTE_NAMEDTUPLESTORE, RTE_RELATION, RTE_RESULT, RTE_SUBQUERY, RTE_TABLEFUNC, and RTE_VALUES.

◆ range_table_walker_impl()

bool range_table_walker_impl ( List rtable,
tree_walker_callback  walker,
void context,
int  flags 
)

Definition at line 2860 of file nodeFuncs.c.

2864{
2865 ListCell *rt;
2866
2867 foreach(rt, rtable)
2868 {
2870
2871 if (range_table_entry_walker(rte, walker, context, flags))
2872 return true;
2873 }
2874 return false;
2875}
#define range_table_entry_walker(r, w, c, f)
Definition nodeFuncs.h:168

References fb(), lfirst_node, and range_table_entry_walker.

◆ raw_expression_tree_walker_impl()

bool raw_expression_tree_walker_impl ( Node node,
tree_walker_callback  walker,
void context 
)

Definition at line 4086 of file nodeFuncs.c.

4089{
4090 ListCell *temp;
4091
4092 /*
4093 * The walker has already visited the current node, and so we need only
4094 * recurse into any sub-nodes it has.
4095 */
4096 if (node == NULL)
4097 return false;
4098
4099 /* Guard against stack overflow due to overly complex expressions */
4101
4102 switch (nodeTag(node))
4103 {
4104 case T_JsonFormat:
4105 case T_SetToDefault:
4106 case T_CurrentOfExpr:
4107 case T_SQLValueFunction:
4108 case T_Integer:
4109 case T_Float:
4110 case T_Boolean:
4111 case T_String:
4112 case T_BitString:
4113 case T_ParamRef:
4114 case T_A_Const:
4115 case T_A_Star:
4116 case T_MergeSupportFunc:
4117 case T_ReturningOption:
4118 /* primitive node types with no subnodes */
4119 break;
4120 case T_Alias:
4121 /* we assume the colnames list isn't interesting */
4122 break;
4123 case T_RangeVar:
4124 return WALK(((RangeVar *) node)->alias);
4125 case T_GroupingFunc:
4126 return WALK(((GroupingFunc *) node)->args);
4127 case T_SubLink:
4128 {
4129 SubLink *sublink = (SubLink *) node;
4130
4131 if (WALK(sublink->testexpr))
4132 return true;
4133 /* we assume the operName is not interesting */
4134 if (WALK(sublink->subselect))
4135 return true;
4136 }
4137 break;
4138 case T_CaseExpr:
4139 {
4140 CaseExpr *caseexpr = (CaseExpr *) node;
4141
4142 if (WALK(caseexpr->arg))
4143 return true;
4144 /* we assume walker doesn't care about CaseWhens, either */
4145 foreach(temp, caseexpr->args)
4146 {
4148
4149 if (WALK(when->expr))
4150 return true;
4151 if (WALK(when->result))
4152 return true;
4153 }
4154 if (WALK(caseexpr->defresult))
4155 return true;
4156 }
4157 break;
4158 case T_RowExpr:
4159 /* Assume colnames isn't interesting */
4160 return WALK(((RowExpr *) node)->args);
4161 case T_CoalesceExpr:
4162 return WALK(((CoalesceExpr *) node)->args);
4163 case T_MinMaxExpr:
4164 return WALK(((MinMaxExpr *) node)->args);
4165 case T_XmlExpr:
4166 {
4167 XmlExpr *xexpr = (XmlExpr *) node;
4168
4169 if (WALK(xexpr->named_args))
4170 return true;
4171 /* we assume walker doesn't care about arg_names */
4172 if (WALK(xexpr->args))
4173 return true;
4174 }
4175 break;
4176 case T_JsonReturning:
4177 return WALK(((JsonReturning *) node)->format);
4178 case T_JsonValueExpr:
4179 {
4180 JsonValueExpr *jve = (JsonValueExpr *) node;
4181
4182 if (WALK(jve->raw_expr))
4183 return true;
4184 if (WALK(jve->formatted_expr))
4185 return true;
4186 if (WALK(jve->format))
4187 return true;
4188 }
4189 break;
4190 case T_JsonParseExpr:
4191 {
4192 JsonParseExpr *jpe = (JsonParseExpr *) node;
4193
4194 if (WALK(jpe->expr))
4195 return true;
4196 if (WALK(jpe->output))
4197 return true;
4198 }
4199 break;
4200 case T_JsonScalarExpr:
4201 {
4202 JsonScalarExpr *jse = (JsonScalarExpr *) node;
4203
4204 if (WALK(jse->expr))
4205 return true;
4206 if (WALK(jse->output))
4207 return true;
4208 }
4209 break;
4211 {
4213
4214 if (WALK(jse->expr))
4215 return true;
4216 if (WALK(jse->output))
4217 return true;
4218 }
4219 break;
4221 {
4223
4224 if (WALK(ctor->args))
4225 return true;
4226 if (WALK(ctor->func))
4227 return true;
4228 if (WALK(ctor->coercion))
4229 return true;
4230 if (WALK(ctor->returning))
4231 return true;
4232 }
4233 break;
4234 case T_JsonIsPredicate:
4235 return WALK(((JsonIsPredicate *) node)->expr);
4236 case T_JsonArgument:
4237 return WALK(((JsonArgument *) node)->val);
4238 case T_JsonFuncExpr:
4239 {
4240 JsonFuncExpr *jfe = (JsonFuncExpr *) node;
4241
4242 if (WALK(jfe->context_item))
4243 return true;
4244 if (WALK(jfe->pathspec))
4245 return true;
4246 if (WALK(jfe->passing))
4247 return true;
4248 if (WALK(jfe->output))
4249 return true;
4250 if (WALK(jfe->on_empty))
4251 return true;
4252 if (WALK(jfe->on_error))
4253 return true;
4254 }
4255 break;
4256 case T_JsonBehavior:
4257 {
4258 JsonBehavior *jb = (JsonBehavior *) node;
4259
4260 if (WALK(jb->expr))
4261 return true;
4262 }
4263 break;
4264 case T_JsonTable:
4265 {
4266 JsonTable *jt = (JsonTable *) node;
4267
4268 if (WALK(jt->context_item))
4269 return true;
4270 if (WALK(jt->pathspec))
4271 return true;
4272 if (WALK(jt->passing))
4273 return true;
4274 if (WALK(jt->columns))
4275 return true;
4276 if (WALK(jt->on_error))
4277 return true;
4278 }
4279 break;
4280 case T_JsonTableColumn:
4281 {
4283
4284 if (WALK(jtc->typeName))
4285 return true;
4286 if (WALK(jtc->on_empty))
4287 return true;
4288 if (WALK(jtc->on_error))
4289 return true;
4290 if (WALK(jtc->columns))
4291 return true;
4292 }
4293 break;
4295 return WALK(((JsonTablePathSpec *) node)->string);
4296 case T_NullTest:
4297 return WALK(((NullTest *) node)->arg);
4298 case T_BooleanTest:
4299 return WALK(((BooleanTest *) node)->arg);
4300 case T_JoinExpr:
4301 {
4302 JoinExpr *join = (JoinExpr *) node;
4303
4304 if (WALK(join->larg))
4305 return true;
4306 if (WALK(join->rarg))
4307 return true;
4308 if (WALK(join->quals))
4309 return true;
4310 if (WALK(join->alias))
4311 return true;
4312 /* using list is deemed uninteresting */
4313 }
4314 break;
4315 case T_IntoClause:
4316 {
4317 IntoClause *into = (IntoClause *) node;
4318
4319 if (WALK(into->rel))
4320 return true;
4321 /* colNames, options are deemed uninteresting */
4322 /* viewQuery should be null in raw parsetree, but check it */
4323 if (WALK(into->viewQuery))
4324 return true;
4325 }
4326 break;
4327 case T_List:
4328 foreach(temp, (List *) node)
4329 {
4330 if (WALK((Node *) lfirst(temp)))
4331 return true;
4332 }
4333 break;
4334 case T_InsertStmt:
4335 {
4336 InsertStmt *stmt = (InsertStmt *) node;
4337
4338 if (WALK(stmt->relation))
4339 return true;
4340 if (WALK(stmt->cols))
4341 return true;
4342 if (WALK(stmt->selectStmt))
4343 return true;
4344 if (WALK(stmt->onConflictClause))
4345 return true;
4346 if (WALK(stmt->returningClause))
4347 return true;
4348 if (WALK(stmt->withClause))
4349 return true;
4350 }
4351 break;
4352 case T_DeleteStmt:
4353 {
4354 DeleteStmt *stmt = (DeleteStmt *) node;
4355
4356 if (WALK(stmt->relation))
4357 return true;
4358 if (WALK(stmt->usingClause))
4359 return true;
4360 if (WALK(stmt->whereClause))
4361 return true;
4362 if (WALK(stmt->returningClause))
4363 return true;
4364 if (WALK(stmt->withClause))
4365 return true;
4366 }
4367 break;
4368 case T_UpdateStmt:
4369 {
4370 UpdateStmt *stmt = (UpdateStmt *) node;
4371
4372 if (WALK(stmt->relation))
4373 return true;
4374 if (WALK(stmt->targetList))
4375 return true;
4376 if (WALK(stmt->whereClause))
4377 return true;
4378 if (WALK(stmt->fromClause))
4379 return true;
4380 if (WALK(stmt->returningClause))
4381 return true;
4382 if (WALK(stmt->withClause))
4383 return true;
4384 }
4385 break;
4386 case T_MergeStmt:
4387 {
4388 MergeStmt *stmt = (MergeStmt *) node;
4389
4390 if (WALK(stmt->relation))
4391 return true;
4392 if (WALK(stmt->sourceRelation))
4393 return true;
4394 if (WALK(stmt->joinCondition))
4395 return true;
4396 if (WALK(stmt->mergeWhenClauses))
4397 return true;
4398 if (WALK(stmt->returningClause))
4399 return true;
4400 if (WALK(stmt->withClause))
4401 return true;
4402 }
4403 break;
4404 case T_MergeWhenClause:
4405 {
4407
4408 if (WALK(mergeWhenClause->condition))
4409 return true;
4410 if (WALK(mergeWhenClause->targetList))
4411 return true;
4412 if (WALK(mergeWhenClause->values))
4413 return true;
4414 }
4415 break;
4416 case T_ReturningClause:
4417 {
4418 ReturningClause *returning = (ReturningClause *) node;
4419
4420 if (WALK(returning->options))
4421 return true;
4422 if (WALK(returning->exprs))
4423 return true;
4424 }
4425 break;
4426 case T_SelectStmt:
4427 {
4428 SelectStmt *stmt = (SelectStmt *) node;
4429
4430 if (WALK(stmt->distinctClause))
4431 return true;
4432 if (WALK(stmt->intoClause))
4433 return true;
4434 if (WALK(stmt->targetList))
4435 return true;
4436 if (WALK(stmt->fromClause))
4437 return true;
4438 if (WALK(stmt->whereClause))
4439 return true;
4440 if (WALK(stmt->groupClause))
4441 return true;
4442 if (WALK(stmt->havingClause))
4443 return true;
4444 if (WALK(stmt->windowClause))
4445 return true;
4446 if (WALK(stmt->valuesLists))
4447 return true;
4448 if (WALK(stmt->sortClause))
4449 return true;
4450 if (WALK(stmt->limitOffset))
4451 return true;
4452 if (WALK(stmt->limitCount))
4453 return true;
4454 if (WALK(stmt->lockingClause))
4455 return true;
4456 if (WALK(stmt->withClause))
4457 return true;
4458 if (WALK(stmt->larg))
4459 return true;
4460 if (WALK(stmt->rarg))
4461 return true;
4462 }
4463 break;
4464 case T_PLAssignStmt:
4465 {
4466 PLAssignStmt *stmt = (PLAssignStmt *) node;
4467
4468 if (WALK(stmt->indirection))
4469 return true;
4470 if (WALK(stmt->val))
4471 return true;
4472 }
4473 break;
4474 case T_A_Expr:
4475 {
4476 A_Expr *expr = (A_Expr *) node;
4477
4478 if (WALK(expr->lexpr))
4479 return true;
4480 if (WALK(expr->rexpr))
4481 return true;
4482 /* operator name is deemed uninteresting */
4483 }
4484 break;
4485 case T_BoolExpr:
4486 {
4487 BoolExpr *expr = (BoolExpr *) node;
4488
4489 if (WALK(expr->args))
4490 return true;
4491 }
4492 break;
4493 case T_ColumnRef:
4494 /* we assume the fields contain nothing interesting */
4495 break;
4496 case T_FuncCall:
4497 {
4498 FuncCall *fcall = (FuncCall *) node;
4499
4500 if (WALK(fcall->args))
4501 return true;
4502 if (WALK(fcall->agg_order))
4503 return true;
4504 if (WALK(fcall->agg_filter))
4505 return true;
4506 if (WALK(fcall->over))
4507 return true;
4508 /* function name is deemed uninteresting */
4509 }
4510 break;
4511 case T_NamedArgExpr:
4512 return WALK(((NamedArgExpr *) node)->arg);
4513 case T_A_Indices:
4514 {
4515 A_Indices *indices = (A_Indices *) node;
4516
4517 if (WALK(indices->lidx))
4518 return true;
4519 if (WALK(indices->uidx))
4520 return true;
4521 }
4522 break;
4523 case T_A_Indirection:
4524 {
4525 A_Indirection *indir = (A_Indirection *) node;
4526
4527 if (WALK(indir->arg))
4528 return true;
4529 if (WALK(indir->indirection))
4530 return true;
4531 }
4532 break;
4533 case T_A_ArrayExpr:
4534 return WALK(((A_ArrayExpr *) node)->elements);
4535 case T_ResTarget:
4536 {
4537 ResTarget *rt = (ResTarget *) node;
4538
4539 if (WALK(rt->indirection))
4540 return true;
4541 if (WALK(rt->val))
4542 return true;
4543 }
4544 break;
4545 case T_MultiAssignRef:
4546 return WALK(((MultiAssignRef *) node)->source);
4547 case T_TypeCast:
4548 {
4549 TypeCast *tc = (TypeCast *) node;
4550
4551 if (WALK(tc->arg))
4552 return true;
4553 if (WALK(tc->typeName))
4554 return true;
4555 }
4556 break;
4557 case T_CollateClause:
4558 return WALK(((CollateClause *) node)->arg);
4559 case T_SortBy:
4560 return WALK(((SortBy *) node)->node);
4561 case T_WindowDef:
4562 {
4563 WindowDef *wd = (WindowDef *) node;
4564
4565 if (WALK(wd->partitionClause))
4566 return true;
4567 if (WALK(wd->orderClause))
4568 return true;
4569 if (WALK(wd->startOffset))
4570 return true;
4571 if (WALK(wd->endOffset))
4572 return true;
4573 }
4574 break;
4575 case T_RangeSubselect:
4576 {
4577 RangeSubselect *rs = (RangeSubselect *) node;
4578
4579 if (WALK(rs->subquery))
4580 return true;
4581 if (WALK(rs->alias))
4582 return true;
4583 }
4584 break;
4585 case T_RangeFunction:
4586 {
4587 RangeFunction *rf = (RangeFunction *) node;
4588
4589 if (WALK(rf->functions))
4590 return true;
4591 if (WALK(rf->alias))
4592 return true;
4593 if (WALK(rf->coldeflist))
4594 return true;
4595 }
4596 break;
4597 case T_RangeTableSample:
4598 {
4600
4601 if (WALK(rts->relation))
4602 return true;
4603 /* method name is deemed uninteresting */
4604 if (WALK(rts->args))
4605 return true;
4606 if (WALK(rts->repeatable))
4607 return true;
4608 }
4609 break;
4610 case T_RangeTableFunc:
4611 {
4612 RangeTableFunc *rtf = (RangeTableFunc *) node;
4613
4614 if (WALK(rtf->docexpr))
4615 return true;
4616 if (WALK(rtf->rowexpr))
4617 return true;
4618 if (WALK(rtf->namespaces))
4619 return true;
4620 if (WALK(rtf->columns))
4621 return true;
4622 if (WALK(rtf->alias))
4623 return true;
4624 }
4625 break;
4627 {
4629
4630 if (WALK(rtfc->colexpr))
4631 return true;
4632 if (WALK(rtfc->coldefexpr))
4633 return true;
4634 }
4635 break;
4636 case T_RangeGraphTable:
4637 {
4639
4640 if (WALK(rgt->graph_pattern))
4641 return true;
4642 if (WALK(rgt->columns))
4643 return true;
4644 if (WALK(rgt->alias))
4645 return true;
4646 }
4647 break;
4648 case T_TypeName:
4649 {
4650 TypeName *tn = (TypeName *) node;
4651
4652 if (WALK(tn->typmods))
4653 return true;
4654 if (WALK(tn->arrayBounds))
4655 return true;
4656 /* type name itself is deemed uninteresting */
4657 }
4658 break;
4659 case T_ColumnDef:
4660 {
4661 ColumnDef *coldef = (ColumnDef *) node;
4662
4663 if (WALK(coldef->typeName))
4664 return true;
4665 if (WALK(coldef->raw_default))
4666 return true;
4667 if (WALK(coldef->collClause))
4668 return true;
4669 /* for now, constraints are ignored */
4670 }
4671 break;
4672 case T_IndexElem:
4673 {
4674 IndexElem *indelem = (IndexElem *) node;
4675
4676 if (WALK(indelem->expr))
4677 return true;
4678 /* collation and opclass names are deemed uninteresting */
4679 }
4680 break;
4681 case T_GroupingSet:
4682 return WALK(((GroupingSet *) node)->content);
4683 case T_LockingClause:
4684 return WALK(((LockingClause *) node)->lockedRels);
4685 case T_XmlSerialize:
4686 {
4687 XmlSerialize *xs = (XmlSerialize *) node;
4688
4689 if (WALK(xs->expr))
4690 return true;
4691 if (WALK(xs->typeName))
4692 return true;
4693 }
4694 break;
4695 case T_WithClause:
4696 return WALK(((WithClause *) node)->ctes);
4697 case T_InferClause:
4698 {
4699 InferClause *stmt = (InferClause *) node;
4700
4701 if (WALK(stmt->indexElems))
4702 return true;
4703 if (WALK(stmt->whereClause))
4704 return true;
4705 }
4706 break;
4707 case T_OnConflictClause:
4708 {
4710
4711 if (WALK(stmt->infer))
4712 return true;
4713 if (WALK(stmt->targetList))
4714 return true;
4715 if (WALK(stmt->whereClause))
4716 return true;
4717 }
4718 break;
4719 case T_CommonTableExpr:
4720 /* search_clause and cycle_clause are not interesting here */
4721 return WALK(((CommonTableExpr *) node)->ctequery);
4722 case T_JsonOutput:
4723 {
4724 JsonOutput *out = (JsonOutput *) node;
4725
4726 if (WALK(out->typeName))
4727 return true;
4728 if (WALK(out->returning))
4729 return true;
4730 }
4731 break;
4732 case T_JsonKeyValue:
4733 {
4734 JsonKeyValue *jkv = (JsonKeyValue *) node;
4735
4736 if (WALK(jkv->key))
4737 return true;
4738 if (WALK(jkv->value))
4739 return true;
4740 }
4741 break;
4743 {
4745
4746 if (WALK(joc->output))
4747 return true;
4748 if (WALK(joc->exprs))
4749 return true;
4750 }
4751 break;
4753 {
4755
4756 if (WALK(jac->output))
4757 return true;
4758 if (WALK(jac->exprs))
4759 return true;
4760 }
4761 break;
4763 {
4765
4766 if (WALK(ctor->output))
4767 return true;
4768 if (WALK(ctor->agg_order))
4769 return true;
4770 if (WALK(ctor->agg_filter))
4771 return true;
4772 if (WALK(ctor->over))
4773 return true;
4774 }
4775 break;
4776 case T_JsonObjectAgg:
4777 {
4778 JsonObjectAgg *joa = (JsonObjectAgg *) node;
4779
4780 if (WALK(joa->constructor))
4781 return true;
4782 if (WALK(joa->arg))
4783 return true;
4784 }
4785 break;
4786 case T_JsonArrayAgg:
4787 {
4788 JsonArrayAgg *jaa = (JsonArrayAgg *) node;
4789
4790 if (WALK(jaa->constructor))
4791 return true;
4792 if (WALK(jaa->arg))
4793 return true;
4794 }
4795 break;
4797 {
4799
4800 if (WALK(jaqc->output))
4801 return true;
4802 if (WALK(jaqc->query))
4803 return true;
4804 }
4805 break;
4807 {
4809
4810 if (WALK(gep->subexpr))
4811 return true;
4812 if (WALK(gep->whereClause))
4813 return true;
4814 }
4815 break;
4816 case T_GraphPattern:
4817 {
4818 GraphPattern *gp = (GraphPattern *) node;
4819
4820 if (WALK(gp->path_pattern_list))
4821 return true;
4822 if (WALK(gp->whereClause))
4823 return true;
4824 }
4825 break;
4826 default:
4827 elog(ERROR, "unrecognized node type: %d",
4828 (int) nodeTag(node));
4829 break;
4830 }
4831 return false;
4832}
#define stmt
long val
Definition informix.c:689
static char format
Node * lexpr
Definition parsenodes.h:356
Node * rexpr
Definition parsenodes.h:357
Node * uidx
Definition parsenodes.h:490
Node * lidx
Definition parsenodes.h:489
Node * agg_filter
Definition parsenodes.h:457
List * agg_order
Definition parsenodes.h:456
List * args
Definition parsenodes.h:455
struct WindowDef * over
Definition parsenodes.h:458
RangeVar * rel
Definition primnodes.h:164
JsonReturning * returning
TypeName * typeName
JsonBehavior * on_error
List * columns
JsonTablePathSpec * pathspec
List * passing
JsonValueExpr * context_item

References FuncCall::agg_filter, FuncCall::agg_order, RangeSubselect::alias, arg, FuncCall::args, BoolExpr::args, XmlExpr::args, check_stack_depth(), JsonTable::columns, JsonTable::context_item, elog, ERROR, ReturningClause::exprs, fb(), format, JoinExpr::larg, A_Expr::lexpr, lfirst, lfirst_node, A_Indices::lidx, XmlExpr::named_args, nodeTag, JsonTable::on_error, ReturningClause::options, FuncCall::over, JsonTable::passing, JsonTable::pathspec, JoinExpr::quals, JoinExpr::rarg, IntoClause::rel, JsonOutput::returning, A_Expr::rexpr, source, stmt, RangeSubselect::subquery, JsonOutput::typeName, A_Indices::uidx, val, and WALK.

◆ relabel_to_typmod()

Node * relabel_to_typmod ( Node expr,
int32  typmod 
)

Definition at line 694 of file nodeFuncs.c.

695{
696 return applyRelabelType(expr, exprType(expr), typmod, exprCollation(expr),
697 COERCE_EXPLICIT_CAST, -1, false);
698}
Node * applyRelabelType(Node *arg, Oid rtype, int32 rtypmod, Oid rcollid, CoercionForm rformat, int rlocation, bool overwrite_ok)
Definition nodeFuncs.c:641

References applyRelabelType(), COERCE_EXPLICIT_CAST, exprCollation(), and exprType().

Referenced by interval_support(), numeric_support(), TemporalSimplify(), varbit_support(), and varchar_support().

◆ set_opfuncid()

◆ set_sa_opfuncid()

void set_sa_opfuncid ( ScalarArrayOpExpr opexpr)

Definition at line 1901 of file nodeFuncs.c.

1902{
1903 if (opexpr->opfuncid == InvalidOid)
1904 opexpr->opfuncid = get_opcode(opexpr->opno);
1905}

References get_opcode(), InvalidOid, and ScalarArrayOpExpr::opno.

Referenced by check_functions_in_node(), cost_qual_eval_walker(), eval_const_expressions_mutator(), fix_expr_common(), fix_opfuncids_walker(), and is_strict_saop().

◆ strip_implicit_coercions()

Node * strip_implicit_coercions ( Node node)

Definition at line 710 of file nodeFuncs.c.

711{
712 if (node == NULL)
713 return NULL;
714 if (IsA(node, FuncExpr))
715 {
716 FuncExpr *f = (FuncExpr *) node;
717
718 if (f->funcformat == COERCE_IMPLICIT_CAST)
720 }
721 else if (IsA(node, RelabelType))
722 {
723 RelabelType *r = (RelabelType *) node;
724
725 if (r->relabelformat == COERCE_IMPLICIT_CAST)
726 return strip_implicit_coercions((Node *) r->arg);
727 }
728 else if (IsA(node, CoerceViaIO))
729 {
730 CoerceViaIO *c = (CoerceViaIO *) node;
731
732 if (c->coerceformat == COERCE_IMPLICIT_CAST)
733 return strip_implicit_coercions((Node *) c->arg);
734 }
735 else if (IsA(node, ArrayCoerceExpr))
736 {
738
739 if (c->coerceformat == COERCE_IMPLICIT_CAST)
740 return strip_implicit_coercions((Node *) c->arg);
741 }
742 else if (IsA(node, ConvertRowtypeExpr))
743 {
745
746 if (c->convertformat == COERCE_IMPLICIT_CAST)
747 return strip_implicit_coercions((Node *) c->arg);
748 }
749 else if (IsA(node, CoerceToDomain))
750 {
751 CoerceToDomain *c = (CoerceToDomain *) node;
752
753 if (c->coercionformat == COERCE_IMPLICIT_CAST)
754 return strip_implicit_coercions((Node *) c->arg);
755 }
756 return node;
757}
Node * strip_implicit_coercions(Node *node)
Definition nodeFuncs.c:710
char * c

References RelabelType::arg, FuncExpr::args, COERCE_IMPLICIT_CAST, fb(), IsA, linitial, and strip_implicit_coercions().

Referenced by AcquireRewriteLocks(), ATExecAlterColumnType(), findTargetlistEntrySQL99(), foreign_expr_walker(), get_rule_expr(), get_update_query_targetlist_def(), and strip_implicit_coercions().