1 /*-------------------------------------------------------------------------
4 * Copy functions for Postgres tree nodes.
6 * NOTE: we currently support copying all node types found in parse and
7 * plan trees. We do not support copying executor state trees; there
8 * is no need for that, and no point in maintaining all the code that
9 * would be needed. We also do not support copying Path trees, mainly
10 * because the circular linkages between RelOptInfo and Path nodes can't
11 * be handled easily in a simple depth-first traversal.
14 * Portions Copyright (c) 1996-2007, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.383 2007/10/11 18:05:26 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "nodes/plannodes.h"
26 #include "nodes/relation.h"
27 #include "utils/datum.h"
31 * Macros to simplify copying of different kinds of fields. Use these
32 * wherever possible to reduce the chance for silly typos. Note that these
33 * hard-wire the convention that the local variables in a Copy routine are
34 * named 'newnode' and 'from'.
37 /* Copy a simple scalar field (int, float, bool, enum, etc) */
38 #define COPY_SCALAR_FIELD(fldname) \
39 (newnode->fldname = from->fldname)
41 /* Copy a field that is a pointer to some kind of Node or Node tree */
42 #define COPY_NODE_FIELD(fldname) \
43 (newnode->fldname = copyObject(from->fldname))
45 /* Copy a field that is a pointer to a Bitmapset */
46 #define COPY_BITMAPSET_FIELD(fldname) \
47 (newnode->fldname = bms_copy(from->fldname))
49 /* Copy a field that is a pointer to a C string, or perhaps NULL */
50 #define COPY_STRING_FIELD(fldname) \
51 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
53 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
54 #define COPY_POINTER_FIELD(fldname, sz) \
57 newnode->fldname = palloc(_size); \
58 memcpy(newnode->fldname, from->fldname, _size); \
62 /* ****************************************************************
63 * plannodes.h copy functions
64 * ****************************************************************
71 _copyPlannedStmt(PlannedStmt *from)
73 PlannedStmt *newnode = makeNode(PlannedStmt);
75 COPY_SCALAR_FIELD(commandType);
76 COPY_SCALAR_FIELD(canSetTag);
77 COPY_NODE_FIELD(planTree);
78 COPY_NODE_FIELD(rtable);
79 COPY_NODE_FIELD(resultRelations);
80 COPY_NODE_FIELD(utilityStmt);
81 COPY_NODE_FIELD(intoClause);
82 COPY_NODE_FIELD(subplans);
83 COPY_BITMAPSET_FIELD(rewindPlanIDs);
84 COPY_NODE_FIELD(returningLists);
85 COPY_NODE_FIELD(rowMarks);
86 COPY_NODE_FIELD(relationOids);
87 COPY_SCALAR_FIELD(nParamExec);
95 * This function copies the fields of the Plan node. It is used by
96 * all the copy functions for classes which inherit from Plan.
99 CopyPlanFields(Plan *from, Plan *newnode)
101 COPY_SCALAR_FIELD(startup_cost);
102 COPY_SCALAR_FIELD(total_cost);
103 COPY_SCALAR_FIELD(plan_rows);
104 COPY_SCALAR_FIELD(plan_width);
105 COPY_NODE_FIELD(targetlist);
106 COPY_NODE_FIELD(qual);
107 COPY_NODE_FIELD(lefttree);
108 COPY_NODE_FIELD(righttree);
109 COPY_NODE_FIELD(initPlan);
110 COPY_BITMAPSET_FIELD(extParam);
111 COPY_BITMAPSET_FIELD(allParam);
118 _copyPlan(Plan *from)
120 Plan *newnode = makeNode(Plan);
123 * copy node superclass fields
125 CopyPlanFields(from, newnode);
135 _copyResult(Result *from)
137 Result *newnode = makeNode(Result);
140 * copy node superclass fields
142 CopyPlanFields((Plan *) from, (Plan *) newnode);
145 * copy remainder of node
147 COPY_NODE_FIELD(resconstantqual);
156 _copyAppend(Append *from)
158 Append *newnode = makeNode(Append);
161 * copy node superclass fields
163 CopyPlanFields((Plan *) from, (Plan *) newnode);
166 * copy remainder of node
168 COPY_NODE_FIELD(appendplans);
169 COPY_SCALAR_FIELD(isTarget);
178 _copyBitmapAnd(BitmapAnd *from)
180 BitmapAnd *newnode = makeNode(BitmapAnd);
183 * copy node superclass fields
185 CopyPlanFields((Plan *) from, (Plan *) newnode);
188 * copy remainder of node
190 COPY_NODE_FIELD(bitmapplans);
199 _copyBitmapOr(BitmapOr *from)
201 BitmapOr *newnode = makeNode(BitmapOr);
204 * copy node superclass fields
206 CopyPlanFields((Plan *) from, (Plan *) newnode);
209 * copy remainder of node
211 COPY_NODE_FIELD(bitmapplans);
220 * This function copies the fields of the Scan node. It is used by
221 * all the copy functions for classes which inherit from Scan.
224 CopyScanFields(Scan *from, Scan *newnode)
226 CopyPlanFields((Plan *) from, (Plan *) newnode);
228 COPY_SCALAR_FIELD(scanrelid);
235 _copyScan(Scan *from)
237 Scan *newnode = makeNode(Scan);
240 * copy node superclass fields
242 CopyScanFields((Scan *) from, (Scan *) newnode);
251 _copySeqScan(SeqScan *from)
253 SeqScan *newnode = makeNode(SeqScan);
256 * copy node superclass fields
258 CopyScanFields((Scan *) from, (Scan *) newnode);
267 _copyIndexScan(IndexScan *from)
269 IndexScan *newnode = makeNode(IndexScan);
272 * copy node superclass fields
274 CopyScanFields((Scan *) from, (Scan *) newnode);
277 * copy remainder of node
279 COPY_SCALAR_FIELD(indexid);
280 COPY_NODE_FIELD(indexqual);
281 COPY_NODE_FIELD(indexqualorig);
282 COPY_NODE_FIELD(indexstrategy);
283 COPY_NODE_FIELD(indexsubtype);
284 COPY_SCALAR_FIELD(indexorderdir);
290 * _copyBitmapIndexScan
292 static BitmapIndexScan *
293 _copyBitmapIndexScan(BitmapIndexScan *from)
295 BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
298 * copy node superclass fields
300 CopyScanFields((Scan *) from, (Scan *) newnode);
303 * copy remainder of node
305 COPY_SCALAR_FIELD(indexid);
306 COPY_NODE_FIELD(indexqual);
307 COPY_NODE_FIELD(indexqualorig);
308 COPY_NODE_FIELD(indexstrategy);
309 COPY_NODE_FIELD(indexsubtype);
315 * _copyBitmapHeapScan
317 static BitmapHeapScan *
318 _copyBitmapHeapScan(BitmapHeapScan *from)
320 BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
323 * copy node superclass fields
325 CopyScanFields((Scan *) from, (Scan *) newnode);
328 * copy remainder of node
330 COPY_NODE_FIELD(bitmapqualorig);
339 _copyTidScan(TidScan *from)
341 TidScan *newnode = makeNode(TidScan);
344 * copy node superclass fields
346 CopyScanFields((Scan *) from, (Scan *) newnode);
349 * copy remainder of node
351 COPY_NODE_FIELD(tidquals);
359 static SubqueryScan *
360 _copySubqueryScan(SubqueryScan *from)
362 SubqueryScan *newnode = makeNode(SubqueryScan);
365 * copy node superclass fields
367 CopyScanFields((Scan *) from, (Scan *) newnode);
370 * copy remainder of node
372 COPY_NODE_FIELD(subplan);
373 COPY_NODE_FIELD(subrtable);
381 static FunctionScan *
382 _copyFunctionScan(FunctionScan *from)
384 FunctionScan *newnode = makeNode(FunctionScan);
387 * copy node superclass fields
389 CopyScanFields((Scan *) from, (Scan *) newnode);
392 * copy remainder of node
394 COPY_NODE_FIELD(funcexpr);
395 COPY_NODE_FIELD(funccolnames);
396 COPY_NODE_FIELD(funccoltypes);
397 COPY_NODE_FIELD(funccoltypmods);
406 _copyValuesScan(ValuesScan *from)
408 ValuesScan *newnode = makeNode(ValuesScan);
411 * copy node superclass fields
413 CopyScanFields((Scan *) from, (Scan *) newnode);
416 * copy remainder of node
418 COPY_NODE_FIELD(values_lists);
426 * This function copies the fields of the Join node. It is used by
427 * all the copy functions for classes which inherit from Join.
430 CopyJoinFields(Join *from, Join *newnode)
432 CopyPlanFields((Plan *) from, (Plan *) newnode);
434 COPY_SCALAR_FIELD(jointype);
435 COPY_NODE_FIELD(joinqual);
443 _copyJoin(Join *from)
445 Join *newnode = makeNode(Join);
448 * copy node superclass fields
450 CopyJoinFields(from, newnode);
460 _copyNestLoop(NestLoop *from)
462 NestLoop *newnode = makeNode(NestLoop);
465 * copy node superclass fields
467 CopyJoinFields((Join *) from, (Join *) newnode);
477 _copyMergeJoin(MergeJoin *from)
479 MergeJoin *newnode = makeNode(MergeJoin);
483 * copy node superclass fields
485 CopyJoinFields((Join *) from, (Join *) newnode);
488 * copy remainder of node
490 COPY_NODE_FIELD(mergeclauses);
491 numCols = list_length(from->mergeclauses);
492 COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
493 COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
494 COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
503 _copyHashJoin(HashJoin *from)
505 HashJoin *newnode = makeNode(HashJoin);
508 * copy node superclass fields
510 CopyJoinFields((Join *) from, (Join *) newnode);
513 * copy remainder of node
515 COPY_NODE_FIELD(hashclauses);
525 _copyMaterial(Material *from)
527 Material *newnode = makeNode(Material);
530 * copy node superclass fields
532 CopyPlanFields((Plan *) from, (Plan *) newnode);
542 _copySort(Sort *from)
544 Sort *newnode = makeNode(Sort);
547 * copy node superclass fields
549 CopyPlanFields((Plan *) from, (Plan *) newnode);
551 COPY_SCALAR_FIELD(numCols);
552 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
553 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
554 COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
564 _copyGroup(Group *from)
566 Group *newnode = makeNode(Group);
568 CopyPlanFields((Plan *) from, (Plan *) newnode);
570 COPY_SCALAR_FIELD(numCols);
571 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
572 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
583 Agg *newnode = makeNode(Agg);
585 CopyPlanFields((Plan *) from, (Plan *) newnode);
587 COPY_SCALAR_FIELD(aggstrategy);
588 COPY_SCALAR_FIELD(numCols);
589 if (from->numCols > 0)
591 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
592 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
594 COPY_SCALAR_FIELD(numGroups);
603 _copyUnique(Unique *from)
605 Unique *newnode = makeNode(Unique);
608 * copy node superclass fields
610 CopyPlanFields((Plan *) from, (Plan *) newnode);
613 * copy remainder of node
615 COPY_SCALAR_FIELD(numCols);
616 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
617 COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
626 _copyHash(Hash *from)
628 Hash *newnode = makeNode(Hash);
631 * copy node superclass fields
633 CopyPlanFields((Plan *) from, (Plan *) newnode);
636 * copy remainder of node
646 _copySetOp(SetOp *from)
648 SetOp *newnode = makeNode(SetOp);
651 * copy node superclass fields
653 CopyPlanFields((Plan *) from, (Plan *) newnode);
656 * copy remainder of node
658 COPY_SCALAR_FIELD(cmd);
659 COPY_SCALAR_FIELD(numCols);
660 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
661 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
662 COPY_SCALAR_FIELD(flagColIdx);
671 _copyLimit(Limit *from)
673 Limit *newnode = makeNode(Limit);
676 * copy node superclass fields
678 CopyPlanFields((Plan *) from, (Plan *) newnode);
681 * copy remainder of node
683 COPY_NODE_FIELD(limitOffset);
684 COPY_NODE_FIELD(limitCount);
689 /* ****************************************************************
690 * primnodes.h copy functions
691 * ****************************************************************
698 _copyAlias(Alias *from)
700 Alias *newnode = makeNode(Alias);
702 COPY_STRING_FIELD(aliasname);
703 COPY_NODE_FIELD(colnames);
712 _copyRangeVar(RangeVar *from)
714 RangeVar *newnode = makeNode(RangeVar);
716 COPY_STRING_FIELD(catalogname);
717 COPY_STRING_FIELD(schemaname);
718 COPY_STRING_FIELD(relname);
719 COPY_SCALAR_FIELD(inhOpt);
720 COPY_SCALAR_FIELD(istemp);
721 COPY_NODE_FIELD(alias);
730 _copyIntoClause(IntoClause *from)
732 IntoClause *newnode = makeNode(IntoClause);
734 COPY_NODE_FIELD(rel);
735 COPY_NODE_FIELD(colNames);
736 COPY_NODE_FIELD(options);
737 COPY_SCALAR_FIELD(onCommit);
738 COPY_STRING_FIELD(tableSpaceName);
744 * We don't need a _copyExpr because Expr is an abstract supertype which
745 * should never actually get instantiated. Also, since it has no common
746 * fields except NodeTag, there's no need for a helper routine to factor
747 * out copying the common fields...
756 Var *newnode = makeNode(Var);
758 COPY_SCALAR_FIELD(varno);
759 COPY_SCALAR_FIELD(varattno);
760 COPY_SCALAR_FIELD(vartype);
761 COPY_SCALAR_FIELD(vartypmod);
762 COPY_SCALAR_FIELD(varlevelsup);
763 COPY_SCALAR_FIELD(varnoold);
764 COPY_SCALAR_FIELD(varoattno);
773 _copyConst(Const *from)
775 Const *newnode = makeNode(Const);
777 COPY_SCALAR_FIELD(consttype);
778 COPY_SCALAR_FIELD(consttypmod);
779 COPY_SCALAR_FIELD(constlen);
781 if (from->constbyval || from->constisnull)
784 * passed by value so just copy the datum. Also, don't try to copy
785 * struct when value is null!
787 newnode->constvalue = from->constvalue;
792 * passed by reference. We need a palloc'd copy.
794 newnode->constvalue = datumCopy(from->constvalue,
799 COPY_SCALAR_FIELD(constisnull);
800 COPY_SCALAR_FIELD(constbyval);
809 _copyParam(Param *from)
811 Param *newnode = makeNode(Param);
813 COPY_SCALAR_FIELD(paramkind);
814 COPY_SCALAR_FIELD(paramid);
815 COPY_SCALAR_FIELD(paramtype);
816 COPY_SCALAR_FIELD(paramtypmod);
825 _copyAggref(Aggref *from)
827 Aggref *newnode = makeNode(Aggref);
829 COPY_SCALAR_FIELD(aggfnoid);
830 COPY_SCALAR_FIELD(aggtype);
831 COPY_NODE_FIELD(args);
832 COPY_SCALAR_FIELD(agglevelsup);
833 COPY_SCALAR_FIELD(aggstar);
834 COPY_SCALAR_FIELD(aggdistinct);
843 _copyArrayRef(ArrayRef *from)
845 ArrayRef *newnode = makeNode(ArrayRef);
847 COPY_SCALAR_FIELD(refarraytype);
848 COPY_SCALAR_FIELD(refelemtype);
849 COPY_SCALAR_FIELD(reftypmod);
850 COPY_NODE_FIELD(refupperindexpr);
851 COPY_NODE_FIELD(reflowerindexpr);
852 COPY_NODE_FIELD(refexpr);
853 COPY_NODE_FIELD(refassgnexpr);
862 _copyFuncExpr(FuncExpr *from)
864 FuncExpr *newnode = makeNode(FuncExpr);
866 COPY_SCALAR_FIELD(funcid);
867 COPY_SCALAR_FIELD(funcresulttype);
868 COPY_SCALAR_FIELD(funcretset);
869 COPY_SCALAR_FIELD(funcformat);
870 COPY_NODE_FIELD(args);
879 _copyOpExpr(OpExpr *from)
881 OpExpr *newnode = makeNode(OpExpr);
883 COPY_SCALAR_FIELD(opno);
884 COPY_SCALAR_FIELD(opfuncid);
885 COPY_SCALAR_FIELD(opresulttype);
886 COPY_SCALAR_FIELD(opretset);
887 COPY_NODE_FIELD(args);
893 * _copyDistinctExpr (same as OpExpr)
895 static DistinctExpr *
896 _copyDistinctExpr(DistinctExpr *from)
898 DistinctExpr *newnode = makeNode(DistinctExpr);
900 COPY_SCALAR_FIELD(opno);
901 COPY_SCALAR_FIELD(opfuncid);
902 COPY_SCALAR_FIELD(opresulttype);
903 COPY_SCALAR_FIELD(opretset);
904 COPY_NODE_FIELD(args);
910 * _copyScalarArrayOpExpr
912 static ScalarArrayOpExpr *
913 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
915 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
917 COPY_SCALAR_FIELD(opno);
918 COPY_SCALAR_FIELD(opfuncid);
919 COPY_SCALAR_FIELD(useOr);
920 COPY_NODE_FIELD(args);
929 _copyBoolExpr(BoolExpr *from)
931 BoolExpr *newnode = makeNode(BoolExpr);
933 COPY_SCALAR_FIELD(boolop);
934 COPY_NODE_FIELD(args);
943 _copySubLink(SubLink *from)
945 SubLink *newnode = makeNode(SubLink);
947 COPY_SCALAR_FIELD(subLinkType);
948 COPY_NODE_FIELD(testexpr);
949 COPY_NODE_FIELD(operName);
950 COPY_NODE_FIELD(subselect);
959 _copySubPlan(SubPlan *from)
961 SubPlan *newnode = makeNode(SubPlan);
963 COPY_SCALAR_FIELD(subLinkType);
964 COPY_NODE_FIELD(testexpr);
965 COPY_NODE_FIELD(paramIds);
966 COPY_SCALAR_FIELD(plan_id);
967 COPY_SCALAR_FIELD(firstColType);
968 COPY_SCALAR_FIELD(useHashTable);
969 COPY_SCALAR_FIELD(unknownEqFalse);
970 COPY_NODE_FIELD(setParam);
971 COPY_NODE_FIELD(parParam);
972 COPY_NODE_FIELD(args);
981 _copyFieldSelect(FieldSelect *from)
983 FieldSelect *newnode = makeNode(FieldSelect);
985 COPY_NODE_FIELD(arg);
986 COPY_SCALAR_FIELD(fieldnum);
987 COPY_SCALAR_FIELD(resulttype);
988 COPY_SCALAR_FIELD(resulttypmod);
997 _copyFieldStore(FieldStore *from)
999 FieldStore *newnode = makeNode(FieldStore);
1001 COPY_NODE_FIELD(arg);
1002 COPY_NODE_FIELD(newvals);
1003 COPY_NODE_FIELD(fieldnums);
1004 COPY_SCALAR_FIELD(resulttype);
1012 static RelabelType *
1013 _copyRelabelType(RelabelType *from)
1015 RelabelType *newnode = makeNode(RelabelType);
1017 COPY_NODE_FIELD(arg);
1018 COPY_SCALAR_FIELD(resulttype);
1019 COPY_SCALAR_FIELD(resulttypmod);
1020 COPY_SCALAR_FIELD(relabelformat);
1028 static CoerceViaIO *
1029 _copyCoerceViaIO(CoerceViaIO *from)
1031 CoerceViaIO *newnode = makeNode(CoerceViaIO);
1033 COPY_NODE_FIELD(arg);
1034 COPY_SCALAR_FIELD(resulttype);
1035 COPY_SCALAR_FIELD(coerceformat);
1041 * _copyArrayCoerceExpr
1043 static ArrayCoerceExpr *
1044 _copyArrayCoerceExpr(ArrayCoerceExpr *from)
1046 ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1048 COPY_NODE_FIELD(arg);
1049 COPY_SCALAR_FIELD(elemfuncid);
1050 COPY_SCALAR_FIELD(resulttype);
1051 COPY_SCALAR_FIELD(resulttypmod);
1052 COPY_SCALAR_FIELD(isExplicit);
1053 COPY_SCALAR_FIELD(coerceformat);
1059 * _copyConvertRowtypeExpr
1061 static ConvertRowtypeExpr *
1062 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
1064 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1066 COPY_NODE_FIELD(arg);
1067 COPY_SCALAR_FIELD(resulttype);
1068 COPY_SCALAR_FIELD(convertformat);
1077 _copyCaseExpr(CaseExpr *from)
1079 CaseExpr *newnode = makeNode(CaseExpr);
1081 COPY_SCALAR_FIELD(casetype);
1082 COPY_NODE_FIELD(arg);
1083 COPY_NODE_FIELD(args);
1084 COPY_NODE_FIELD(defresult);
1093 _copyCaseWhen(CaseWhen *from)
1095 CaseWhen *newnode = makeNode(CaseWhen);
1097 COPY_NODE_FIELD(expr);
1098 COPY_NODE_FIELD(result);
1106 static CaseTestExpr *
1107 _copyCaseTestExpr(CaseTestExpr *from)
1109 CaseTestExpr *newnode = makeNode(CaseTestExpr);
1111 COPY_SCALAR_FIELD(typeId);
1112 COPY_SCALAR_FIELD(typeMod);
1121 _copyArrayExpr(ArrayExpr *from)
1123 ArrayExpr *newnode = makeNode(ArrayExpr);
1125 COPY_SCALAR_FIELD(array_typeid);
1126 COPY_SCALAR_FIELD(element_typeid);
1127 COPY_NODE_FIELD(elements);
1128 COPY_SCALAR_FIELD(multidims);
1137 _copyRowExpr(RowExpr *from)
1139 RowExpr *newnode = makeNode(RowExpr);
1141 COPY_NODE_FIELD(args);
1142 COPY_SCALAR_FIELD(row_typeid);
1143 COPY_SCALAR_FIELD(row_format);
1149 * _copyRowCompareExpr
1151 static RowCompareExpr *
1152 _copyRowCompareExpr(RowCompareExpr *from)
1154 RowCompareExpr *newnode = makeNode(RowCompareExpr);
1156 COPY_SCALAR_FIELD(rctype);
1157 COPY_NODE_FIELD(opnos);
1158 COPY_NODE_FIELD(opfamilies);
1159 COPY_NODE_FIELD(largs);
1160 COPY_NODE_FIELD(rargs);
1168 static CoalesceExpr *
1169 _copyCoalesceExpr(CoalesceExpr *from)
1171 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1173 COPY_SCALAR_FIELD(coalescetype);
1174 COPY_NODE_FIELD(args);
1183 _copyMinMaxExpr(MinMaxExpr *from)
1185 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1187 COPY_SCALAR_FIELD(minmaxtype);
1188 COPY_SCALAR_FIELD(op);
1189 COPY_NODE_FIELD(args);
1198 _copyXmlExpr(XmlExpr *from)
1200 XmlExpr *newnode = makeNode(XmlExpr);
1202 COPY_SCALAR_FIELD(op);
1203 COPY_STRING_FIELD(name);
1204 COPY_NODE_FIELD(named_args);
1205 COPY_NODE_FIELD(arg_names);
1206 COPY_NODE_FIELD(args);
1207 COPY_SCALAR_FIELD(xmloption);
1208 COPY_SCALAR_FIELD(type);
1209 COPY_SCALAR_FIELD(typmod);
1215 * _copyNullIfExpr (same as OpExpr)
1218 _copyNullIfExpr(NullIfExpr *from)
1220 NullIfExpr *newnode = makeNode(NullIfExpr);
1222 COPY_SCALAR_FIELD(opno);
1223 COPY_SCALAR_FIELD(opfuncid);
1224 COPY_SCALAR_FIELD(opresulttype);
1225 COPY_SCALAR_FIELD(opretset);
1226 COPY_NODE_FIELD(args);
1235 _copyNullTest(NullTest *from)
1237 NullTest *newnode = makeNode(NullTest);
1239 COPY_NODE_FIELD(arg);
1240 COPY_SCALAR_FIELD(nulltesttype);
1248 static BooleanTest *
1249 _copyBooleanTest(BooleanTest *from)
1251 BooleanTest *newnode = makeNode(BooleanTest);
1253 COPY_NODE_FIELD(arg);
1254 COPY_SCALAR_FIELD(booltesttype);
1260 * _copyCoerceToDomain
1262 static CoerceToDomain *
1263 _copyCoerceToDomain(CoerceToDomain *from)
1265 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1267 COPY_NODE_FIELD(arg);
1268 COPY_SCALAR_FIELD(resulttype);
1269 COPY_SCALAR_FIELD(resulttypmod);
1270 COPY_SCALAR_FIELD(coercionformat);
1276 * _copyCoerceToDomainValue
1278 static CoerceToDomainValue *
1279 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1281 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1283 COPY_SCALAR_FIELD(typeId);
1284 COPY_SCALAR_FIELD(typeMod);
1292 static SetToDefault *
1293 _copySetToDefault(SetToDefault *from)
1295 SetToDefault *newnode = makeNode(SetToDefault);
1297 COPY_SCALAR_FIELD(typeId);
1298 COPY_SCALAR_FIELD(typeMod);
1304 * _copyCurrentOfExpr
1306 static CurrentOfExpr *
1307 _copyCurrentOfExpr(CurrentOfExpr *from)
1309 CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1311 COPY_SCALAR_FIELD(cvarno);
1312 COPY_STRING_FIELD(cursor_name);
1313 COPY_SCALAR_FIELD(cursor_param);
1321 static TargetEntry *
1322 _copyTargetEntry(TargetEntry *from)
1324 TargetEntry *newnode = makeNode(TargetEntry);
1326 COPY_NODE_FIELD(expr);
1327 COPY_SCALAR_FIELD(resno);
1328 COPY_STRING_FIELD(resname);
1329 COPY_SCALAR_FIELD(ressortgroupref);
1330 COPY_SCALAR_FIELD(resorigtbl);
1331 COPY_SCALAR_FIELD(resorigcol);
1332 COPY_SCALAR_FIELD(resjunk);
1340 static RangeTblRef *
1341 _copyRangeTblRef(RangeTblRef *from)
1343 RangeTblRef *newnode = makeNode(RangeTblRef);
1345 COPY_SCALAR_FIELD(rtindex);
1354 _copyJoinExpr(JoinExpr *from)
1356 JoinExpr *newnode = makeNode(JoinExpr);
1358 COPY_SCALAR_FIELD(jointype);
1359 COPY_SCALAR_FIELD(isNatural);
1360 COPY_NODE_FIELD(larg);
1361 COPY_NODE_FIELD(rarg);
1362 COPY_NODE_FIELD(using);
1363 COPY_NODE_FIELD(quals);
1364 COPY_NODE_FIELD(alias);
1365 COPY_SCALAR_FIELD(rtindex);
1374 _copyFromExpr(FromExpr *from)
1376 FromExpr *newnode = makeNode(FromExpr);
1378 COPY_NODE_FIELD(fromlist);
1379 COPY_NODE_FIELD(quals);
1384 /* ****************************************************************
1385 * relation.h copy functions
1387 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1388 * There are some subsidiary structs that are useful to copy, though.
1389 * ****************************************************************
1396 _copyPathKey(PathKey *from)
1398 PathKey *newnode = makeNode(PathKey);
1400 /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1401 COPY_SCALAR_FIELD(pk_eclass);
1402 COPY_SCALAR_FIELD(pk_opfamily);
1403 COPY_SCALAR_FIELD(pk_strategy);
1404 COPY_SCALAR_FIELD(pk_nulls_first);
1412 static RestrictInfo *
1413 _copyRestrictInfo(RestrictInfo *from)
1415 RestrictInfo *newnode = makeNode(RestrictInfo);
1417 COPY_NODE_FIELD(clause);
1418 COPY_SCALAR_FIELD(is_pushed_down);
1419 COPY_SCALAR_FIELD(outerjoin_delayed);
1420 COPY_SCALAR_FIELD(can_join);
1421 COPY_SCALAR_FIELD(pseudoconstant);
1422 COPY_BITMAPSET_FIELD(clause_relids);
1423 COPY_BITMAPSET_FIELD(required_relids);
1424 COPY_BITMAPSET_FIELD(left_relids);
1425 COPY_BITMAPSET_FIELD(right_relids);
1426 COPY_NODE_FIELD(orclause);
1427 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1428 COPY_SCALAR_FIELD(parent_ec);
1429 COPY_SCALAR_FIELD(eval_cost);
1430 COPY_SCALAR_FIELD(this_selec);
1431 COPY_NODE_FIELD(mergeopfamilies);
1432 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1433 COPY_SCALAR_FIELD(left_ec);
1434 COPY_SCALAR_FIELD(right_ec);
1435 COPY_SCALAR_FIELD(left_em);
1436 COPY_SCALAR_FIELD(right_em);
1437 /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1438 newnode->scansel_cache = NIL;
1439 COPY_SCALAR_FIELD(outer_is_left);
1440 COPY_SCALAR_FIELD(hashjoinoperator);
1441 COPY_SCALAR_FIELD(left_bucketsize);
1442 COPY_SCALAR_FIELD(right_bucketsize);
1448 * _copyOuterJoinInfo
1450 static OuterJoinInfo *
1451 _copyOuterJoinInfo(OuterJoinInfo *from)
1453 OuterJoinInfo *newnode = makeNode(OuterJoinInfo);
1455 COPY_BITMAPSET_FIELD(min_lefthand);
1456 COPY_BITMAPSET_FIELD(min_righthand);
1457 COPY_BITMAPSET_FIELD(syn_lefthand);
1458 COPY_BITMAPSET_FIELD(syn_righthand);
1459 COPY_SCALAR_FIELD(is_full_join);
1460 COPY_SCALAR_FIELD(lhs_strict);
1461 COPY_SCALAR_FIELD(delay_upper_joins);
1469 static InClauseInfo *
1470 _copyInClauseInfo(InClauseInfo *from)
1472 InClauseInfo *newnode = makeNode(InClauseInfo);
1474 COPY_BITMAPSET_FIELD(lefthand);
1475 COPY_BITMAPSET_FIELD(righthand);
1476 COPY_NODE_FIELD(sub_targetlist);
1477 COPY_NODE_FIELD(in_operators);
1483 * _copyAppendRelInfo
1485 static AppendRelInfo *
1486 _copyAppendRelInfo(AppendRelInfo *from)
1488 AppendRelInfo *newnode = makeNode(AppendRelInfo);
1490 COPY_SCALAR_FIELD(parent_relid);
1491 COPY_SCALAR_FIELD(child_relid);
1492 COPY_SCALAR_FIELD(parent_reltype);
1493 COPY_SCALAR_FIELD(child_reltype);
1494 COPY_NODE_FIELD(col_mappings);
1495 COPY_NODE_FIELD(translated_vars);
1496 COPY_SCALAR_FIELD(parent_reloid);
1501 /* ****************************************************************
1502 * parsenodes.h copy functions
1503 * ****************************************************************
1506 static RangeTblEntry *
1507 _copyRangeTblEntry(RangeTblEntry *from)
1509 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1511 COPY_SCALAR_FIELD(rtekind);
1512 COPY_SCALAR_FIELD(relid);
1513 COPY_NODE_FIELD(subquery);
1514 COPY_NODE_FIELD(funcexpr);
1515 COPY_NODE_FIELD(funccoltypes);
1516 COPY_NODE_FIELD(funccoltypmods);
1517 COPY_NODE_FIELD(values_lists);
1518 COPY_SCALAR_FIELD(jointype);
1519 COPY_NODE_FIELD(joinaliasvars);
1520 COPY_NODE_FIELD(alias);
1521 COPY_NODE_FIELD(eref);
1522 COPY_SCALAR_FIELD(inh);
1523 COPY_SCALAR_FIELD(inFromCl);
1524 COPY_SCALAR_FIELD(requiredPerms);
1525 COPY_SCALAR_FIELD(checkAsUser);
1530 static FkConstraint *
1531 _copyFkConstraint(FkConstraint *from)
1533 FkConstraint *newnode = makeNode(FkConstraint);
1535 COPY_STRING_FIELD(constr_name);
1536 COPY_NODE_FIELD(pktable);
1537 COPY_NODE_FIELD(fk_attrs);
1538 COPY_NODE_FIELD(pk_attrs);
1539 COPY_SCALAR_FIELD(fk_matchtype);
1540 COPY_SCALAR_FIELD(fk_upd_action);
1541 COPY_SCALAR_FIELD(fk_del_action);
1542 COPY_SCALAR_FIELD(deferrable);
1543 COPY_SCALAR_FIELD(initdeferred);
1544 COPY_SCALAR_FIELD(skip_validation);
1550 _copySortClause(SortClause *from)
1552 SortClause *newnode = makeNode(SortClause);
1554 COPY_SCALAR_FIELD(tleSortGroupRef);
1555 COPY_SCALAR_FIELD(sortop);
1556 COPY_SCALAR_FIELD(nulls_first);
1561 static GroupClause *
1562 _copyGroupClause(GroupClause *from)
1564 GroupClause *newnode = makeNode(GroupClause);
1566 COPY_SCALAR_FIELD(tleSortGroupRef);
1567 COPY_SCALAR_FIELD(sortop);
1568 COPY_SCALAR_FIELD(nulls_first);
1573 static RowMarkClause *
1574 _copyRowMarkClause(RowMarkClause *from)
1576 RowMarkClause *newnode = makeNode(RowMarkClause);
1578 COPY_SCALAR_FIELD(rti);
1579 COPY_SCALAR_FIELD(forUpdate);
1580 COPY_SCALAR_FIELD(noWait);
1586 _copyAExpr(A_Expr *from)
1588 A_Expr *newnode = makeNode(A_Expr);
1590 COPY_SCALAR_FIELD(kind);
1591 COPY_NODE_FIELD(name);
1592 COPY_NODE_FIELD(lexpr);
1593 COPY_NODE_FIELD(rexpr);
1594 COPY_SCALAR_FIELD(location);
1600 _copyColumnRef(ColumnRef *from)
1602 ColumnRef *newnode = makeNode(ColumnRef);
1604 COPY_NODE_FIELD(fields);
1605 COPY_SCALAR_FIELD(location);
1611 _copyParamRef(ParamRef *from)
1613 ParamRef *newnode = makeNode(ParamRef);
1615 COPY_SCALAR_FIELD(number);
1621 _copyAConst(A_Const *from)
1623 A_Const *newnode = makeNode(A_Const);
1625 /* This part must duplicate _copyValue */
1626 COPY_SCALAR_FIELD(val.type);
1627 switch (from->val.type)
1630 COPY_SCALAR_FIELD(val.val.ival);
1635 COPY_STRING_FIELD(val.val.str);
1641 elog(ERROR, "unrecognized node type: %d",
1642 (int) from->val.type);
1646 COPY_NODE_FIELD(typename);
1652 _copyFuncCall(FuncCall *from)
1654 FuncCall *newnode = makeNode(FuncCall);
1656 COPY_NODE_FIELD(funcname);
1657 COPY_NODE_FIELD(args);
1658 COPY_SCALAR_FIELD(agg_star);
1659 COPY_SCALAR_FIELD(agg_distinct);
1660 COPY_SCALAR_FIELD(location);
1666 _copyAIndices(A_Indices *from)
1668 A_Indices *newnode = makeNode(A_Indices);
1670 COPY_NODE_FIELD(lidx);
1671 COPY_NODE_FIELD(uidx);
1676 static A_Indirection *
1677 _copyA_Indirection(A_Indirection *from)
1679 A_Indirection *newnode = makeNode(A_Indirection);
1681 COPY_NODE_FIELD(arg);
1682 COPY_NODE_FIELD(indirection);
1688 _copyResTarget(ResTarget *from)
1690 ResTarget *newnode = makeNode(ResTarget);
1692 COPY_STRING_FIELD(name);
1693 COPY_NODE_FIELD(indirection);
1694 COPY_NODE_FIELD(val);
1695 COPY_SCALAR_FIELD(location);
1701 _copyTypeName(TypeName *from)
1703 TypeName *newnode = makeNode(TypeName);
1705 COPY_NODE_FIELD(names);
1706 COPY_SCALAR_FIELD(typeid);
1707 COPY_SCALAR_FIELD(timezone);
1708 COPY_SCALAR_FIELD(setof);
1709 COPY_SCALAR_FIELD(pct_type);
1710 COPY_NODE_FIELD(typmods);
1711 COPY_SCALAR_FIELD(typemod);
1712 COPY_NODE_FIELD(arrayBounds);
1713 COPY_SCALAR_FIELD(location);
1719 _copySortBy(SortBy *from)
1721 SortBy *newnode = makeNode(SortBy);
1723 COPY_SCALAR_FIELD(sortby_dir);
1724 COPY_SCALAR_FIELD(sortby_nulls);
1725 COPY_NODE_FIELD(useOp);
1726 COPY_NODE_FIELD(node);
1731 static RangeSubselect *
1732 _copyRangeSubselect(RangeSubselect *from)
1734 RangeSubselect *newnode = makeNode(RangeSubselect);
1736 COPY_NODE_FIELD(subquery);
1737 COPY_NODE_FIELD(alias);
1742 static RangeFunction *
1743 _copyRangeFunction(RangeFunction *from)
1745 RangeFunction *newnode = makeNode(RangeFunction);
1747 COPY_NODE_FIELD(funccallnode);
1748 COPY_NODE_FIELD(alias);
1749 COPY_NODE_FIELD(coldeflist);
1755 _copyTypeCast(TypeCast *from)
1757 TypeCast *newnode = makeNode(TypeCast);
1759 COPY_NODE_FIELD(arg);
1760 COPY_NODE_FIELD(typename);
1766 _copyIndexElem(IndexElem *from)
1768 IndexElem *newnode = makeNode(IndexElem);
1770 COPY_STRING_FIELD(name);
1771 COPY_NODE_FIELD(expr);
1772 COPY_NODE_FIELD(opclass);
1773 COPY_SCALAR_FIELD(ordering);
1774 COPY_SCALAR_FIELD(nulls_ordering);
1780 _copyColumnDef(ColumnDef *from)
1782 ColumnDef *newnode = makeNode(ColumnDef);
1784 COPY_STRING_FIELD(colname);
1785 COPY_NODE_FIELD(typename);
1786 COPY_SCALAR_FIELD(inhcount);
1787 COPY_SCALAR_FIELD(is_local);
1788 COPY_SCALAR_FIELD(is_not_null);
1789 COPY_NODE_FIELD(raw_default);
1790 COPY_STRING_FIELD(cooked_default);
1791 COPY_NODE_FIELD(constraints);
1797 _copyConstraint(Constraint *from)
1799 Constraint *newnode = makeNode(Constraint);
1801 COPY_SCALAR_FIELD(contype);
1802 COPY_STRING_FIELD(name);
1803 COPY_NODE_FIELD(raw_expr);
1804 COPY_STRING_FIELD(cooked_expr);
1805 COPY_NODE_FIELD(keys);
1806 COPY_NODE_FIELD(options);
1807 COPY_STRING_FIELD(indexspace);
1813 _copyDefElem(DefElem *from)
1815 DefElem *newnode = makeNode(DefElem);
1817 COPY_STRING_FIELD(defname);
1818 COPY_NODE_FIELD(arg);
1823 static LockingClause *
1824 _copyLockingClause(LockingClause *from)
1826 LockingClause *newnode = makeNode(LockingClause);
1828 COPY_NODE_FIELD(lockedRels);
1829 COPY_SCALAR_FIELD(forUpdate);
1830 COPY_SCALAR_FIELD(noWait);
1835 static XmlSerialize *
1836 _copyXmlSerialize(XmlSerialize *from)
1838 XmlSerialize *newnode = makeNode(XmlSerialize);
1840 COPY_SCALAR_FIELD(xmloption);
1841 COPY_NODE_FIELD(expr);
1842 COPY_NODE_FIELD(typename);
1848 _copyQuery(Query *from)
1850 Query *newnode = makeNode(Query);
1852 COPY_SCALAR_FIELD(commandType);
1853 COPY_SCALAR_FIELD(querySource);
1854 COPY_SCALAR_FIELD(canSetTag);
1855 COPY_NODE_FIELD(utilityStmt);
1856 COPY_SCALAR_FIELD(resultRelation);
1857 COPY_NODE_FIELD(intoClause);
1858 COPY_SCALAR_FIELD(hasAggs);
1859 COPY_SCALAR_FIELD(hasSubLinks);
1860 COPY_NODE_FIELD(rtable);
1861 COPY_NODE_FIELD(jointree);
1862 COPY_NODE_FIELD(targetList);
1863 COPY_NODE_FIELD(returningList);
1864 COPY_NODE_FIELD(groupClause);
1865 COPY_NODE_FIELD(havingQual);
1866 COPY_NODE_FIELD(distinctClause);
1867 COPY_NODE_FIELD(sortClause);
1868 COPY_NODE_FIELD(limitOffset);
1869 COPY_NODE_FIELD(limitCount);
1870 COPY_NODE_FIELD(rowMarks);
1871 COPY_NODE_FIELD(setOperations);
1877 _copyInsertStmt(InsertStmt *from)
1879 InsertStmt *newnode = makeNode(InsertStmt);
1881 COPY_NODE_FIELD(relation);
1882 COPY_NODE_FIELD(cols);
1883 COPY_NODE_FIELD(selectStmt);
1884 COPY_NODE_FIELD(returningList);
1890 _copyDeleteStmt(DeleteStmt *from)
1892 DeleteStmt *newnode = makeNode(DeleteStmt);
1894 COPY_NODE_FIELD(relation);
1895 COPY_NODE_FIELD(usingClause);
1896 COPY_NODE_FIELD(whereClause);
1897 COPY_NODE_FIELD(returningList);
1903 _copyUpdateStmt(UpdateStmt *from)
1905 UpdateStmt *newnode = makeNode(UpdateStmt);
1907 COPY_NODE_FIELD(relation);
1908 COPY_NODE_FIELD(targetList);
1909 COPY_NODE_FIELD(whereClause);
1910 COPY_NODE_FIELD(fromClause);
1911 COPY_NODE_FIELD(returningList);
1917 _copySelectStmt(SelectStmt *from)
1919 SelectStmt *newnode = makeNode(SelectStmt);
1921 COPY_NODE_FIELD(distinctClause);
1922 COPY_NODE_FIELD(intoClause);
1923 COPY_NODE_FIELD(targetList);
1924 COPY_NODE_FIELD(fromClause);
1925 COPY_NODE_FIELD(whereClause);
1926 COPY_NODE_FIELD(groupClause);
1927 COPY_NODE_FIELD(havingClause);
1928 COPY_NODE_FIELD(valuesLists);
1929 COPY_NODE_FIELD(sortClause);
1930 COPY_NODE_FIELD(limitOffset);
1931 COPY_NODE_FIELD(limitCount);
1932 COPY_NODE_FIELD(lockingClause);
1933 COPY_SCALAR_FIELD(op);
1934 COPY_SCALAR_FIELD(all);
1935 COPY_NODE_FIELD(larg);
1936 COPY_NODE_FIELD(rarg);
1941 static SetOperationStmt *
1942 _copySetOperationStmt(SetOperationStmt *from)
1944 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1946 COPY_SCALAR_FIELD(op);
1947 COPY_SCALAR_FIELD(all);
1948 COPY_NODE_FIELD(larg);
1949 COPY_NODE_FIELD(rarg);
1950 COPY_NODE_FIELD(colTypes);
1951 COPY_NODE_FIELD(colTypmods);
1956 static AlterTableStmt *
1957 _copyAlterTableStmt(AlterTableStmt *from)
1959 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1961 COPY_NODE_FIELD(relation);
1962 COPY_NODE_FIELD(cmds);
1963 COPY_SCALAR_FIELD(relkind);
1968 static AlterTableCmd *
1969 _copyAlterTableCmd(AlterTableCmd *from)
1971 AlterTableCmd *newnode = makeNode(AlterTableCmd);
1973 COPY_SCALAR_FIELD(subtype);
1974 COPY_STRING_FIELD(name);
1975 COPY_NODE_FIELD(def);
1976 COPY_NODE_FIELD(transform);
1977 COPY_SCALAR_FIELD(behavior);
1982 static AlterDomainStmt *
1983 _copyAlterDomainStmt(AlterDomainStmt *from)
1985 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1987 COPY_SCALAR_FIELD(subtype);
1988 COPY_NODE_FIELD(typename);
1989 COPY_STRING_FIELD(name);
1990 COPY_NODE_FIELD(def);
1991 COPY_SCALAR_FIELD(behavior);
1997 _copyGrantStmt(GrantStmt *from)
1999 GrantStmt *newnode = makeNode(GrantStmt);
2001 COPY_SCALAR_FIELD(is_grant);
2002 COPY_SCALAR_FIELD(objtype);
2003 COPY_NODE_FIELD(objects);
2004 COPY_NODE_FIELD(privileges);
2005 COPY_NODE_FIELD(grantees);
2006 COPY_SCALAR_FIELD(grant_option);
2007 COPY_SCALAR_FIELD(behavior);
2012 static PrivGrantee *
2013 _copyPrivGrantee(PrivGrantee *from)
2015 PrivGrantee *newnode = makeNode(PrivGrantee);
2017 COPY_STRING_FIELD(rolname);
2022 static FuncWithArgs *
2023 _copyFuncWithArgs(FuncWithArgs *from)
2025 FuncWithArgs *newnode = makeNode(FuncWithArgs);
2027 COPY_NODE_FIELD(funcname);
2028 COPY_NODE_FIELD(funcargs);
2033 static GrantRoleStmt *
2034 _copyGrantRoleStmt(GrantRoleStmt *from)
2036 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2038 COPY_NODE_FIELD(granted_roles);
2039 COPY_NODE_FIELD(grantee_roles);
2040 COPY_SCALAR_FIELD(is_grant);
2041 COPY_SCALAR_FIELD(admin_opt);
2042 COPY_STRING_FIELD(grantor);
2043 COPY_SCALAR_FIELD(behavior);
2048 static DeclareCursorStmt *
2049 _copyDeclareCursorStmt(DeclareCursorStmt *from)
2051 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2053 COPY_STRING_FIELD(portalname);
2054 COPY_SCALAR_FIELD(options);
2055 COPY_NODE_FIELD(query);
2060 static ClosePortalStmt *
2061 _copyClosePortalStmt(ClosePortalStmt *from)
2063 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2065 COPY_STRING_FIELD(portalname);
2070 static ClusterStmt *
2071 _copyClusterStmt(ClusterStmt *from)
2073 ClusterStmt *newnode = makeNode(ClusterStmt);
2075 COPY_NODE_FIELD(relation);
2076 COPY_STRING_FIELD(indexname);
2082 _copyCopyStmt(CopyStmt *from)
2084 CopyStmt *newnode = makeNode(CopyStmt);
2086 COPY_NODE_FIELD(relation);
2087 COPY_NODE_FIELD(query);
2088 COPY_NODE_FIELD(attlist);
2089 COPY_SCALAR_FIELD(is_from);
2090 COPY_STRING_FIELD(filename);
2091 COPY_NODE_FIELD(options);
2097 _copyCreateStmt(CreateStmt *from)
2099 CreateStmt *newnode = makeNode(CreateStmt);
2101 COPY_NODE_FIELD(relation);
2102 COPY_NODE_FIELD(tableElts);
2103 COPY_NODE_FIELD(inhRelations);
2104 COPY_NODE_FIELD(constraints);
2105 COPY_NODE_FIELD(options);
2106 COPY_SCALAR_FIELD(oncommit);
2107 COPY_STRING_FIELD(tablespacename);
2112 static InhRelation *
2113 _copyInhRelation(InhRelation *from)
2115 InhRelation *newnode = makeNode(InhRelation);
2117 COPY_NODE_FIELD(relation);
2118 COPY_NODE_FIELD(options);
2124 _copyDefineStmt(DefineStmt *from)
2126 DefineStmt *newnode = makeNode(DefineStmt);
2128 COPY_SCALAR_FIELD(kind);
2129 COPY_SCALAR_FIELD(oldstyle);
2130 COPY_NODE_FIELD(defnames);
2131 COPY_NODE_FIELD(args);
2132 COPY_NODE_FIELD(definition);
2138 _copyDropStmt(DropStmt *from)
2140 DropStmt *newnode = makeNode(DropStmt);
2142 COPY_NODE_FIELD(objects);
2143 COPY_SCALAR_FIELD(removeType);
2144 COPY_SCALAR_FIELD(behavior);
2145 COPY_SCALAR_FIELD(missing_ok);
2150 static TruncateStmt *
2151 _copyTruncateStmt(TruncateStmt *from)
2153 TruncateStmt *newnode = makeNode(TruncateStmt);
2155 COPY_NODE_FIELD(relations);
2156 COPY_SCALAR_FIELD(behavior);
2161 static CommentStmt *
2162 _copyCommentStmt(CommentStmt *from)
2164 CommentStmt *newnode = makeNode(CommentStmt);
2166 COPY_SCALAR_FIELD(objtype);
2167 COPY_NODE_FIELD(objname);
2168 COPY_NODE_FIELD(objargs);
2169 COPY_STRING_FIELD(comment);
2175 _copyFetchStmt(FetchStmt *from)
2177 FetchStmt *newnode = makeNode(FetchStmt);
2179 COPY_SCALAR_FIELD(direction);
2180 COPY_SCALAR_FIELD(howMany);
2181 COPY_STRING_FIELD(portalname);
2182 COPY_SCALAR_FIELD(ismove);
2188 _copyIndexStmt(IndexStmt *from)
2190 IndexStmt *newnode = makeNode(IndexStmt);
2192 COPY_STRING_FIELD(idxname);
2193 COPY_NODE_FIELD(relation);
2194 COPY_STRING_FIELD(accessMethod);
2195 COPY_STRING_FIELD(tableSpace);
2196 COPY_NODE_FIELD(indexParams);
2197 COPY_NODE_FIELD(options);
2198 COPY_STRING_FIELD(src_options);
2199 COPY_NODE_FIELD(whereClause);
2200 COPY_SCALAR_FIELD(unique);
2201 COPY_SCALAR_FIELD(primary);
2202 COPY_SCALAR_FIELD(isconstraint);
2203 COPY_SCALAR_FIELD(concurrent);
2208 static CreateFunctionStmt *
2209 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2211 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2213 COPY_SCALAR_FIELD(replace);
2214 COPY_NODE_FIELD(funcname);
2215 COPY_NODE_FIELD(parameters);
2216 COPY_NODE_FIELD(returnType);
2217 COPY_NODE_FIELD(options);
2218 COPY_NODE_FIELD(withClause);
2223 static FunctionParameter *
2224 _copyFunctionParameter(FunctionParameter *from)
2226 FunctionParameter *newnode = makeNode(FunctionParameter);
2228 COPY_STRING_FIELD(name);
2229 COPY_NODE_FIELD(argType);
2230 COPY_SCALAR_FIELD(mode);
2235 static AlterFunctionStmt *
2236 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2238 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2240 COPY_NODE_FIELD(func);
2241 COPY_NODE_FIELD(actions);
2246 static RemoveFuncStmt *
2247 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2249 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2251 COPY_SCALAR_FIELD(kind);
2252 COPY_NODE_FIELD(name);
2253 COPY_NODE_FIELD(args);
2254 COPY_SCALAR_FIELD(behavior);
2255 COPY_SCALAR_FIELD(missing_ok);
2260 static RemoveOpClassStmt *
2261 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2263 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2265 COPY_NODE_FIELD(opclassname);
2266 COPY_STRING_FIELD(amname);
2267 COPY_SCALAR_FIELD(behavior);
2268 COPY_SCALAR_FIELD(missing_ok);
2273 static RemoveOpFamilyStmt *
2274 _copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
2276 RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);
2278 COPY_NODE_FIELD(opfamilyname);
2279 COPY_STRING_FIELD(amname);
2280 COPY_SCALAR_FIELD(behavior);
2281 COPY_SCALAR_FIELD(missing_ok);
2287 _copyRenameStmt(RenameStmt *from)
2289 RenameStmt *newnode = makeNode(RenameStmt);
2291 COPY_SCALAR_FIELD(renameType);
2292 COPY_NODE_FIELD(relation);
2293 COPY_NODE_FIELD(object);
2294 COPY_NODE_FIELD(objarg);
2295 COPY_STRING_FIELD(subname);
2296 COPY_STRING_FIELD(newname);
2301 static AlterObjectSchemaStmt *
2302 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2304 AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2306 COPY_SCALAR_FIELD(objectType);
2307 COPY_NODE_FIELD(relation);
2308 COPY_NODE_FIELD(object);
2309 COPY_NODE_FIELD(objarg);
2310 COPY_STRING_FIELD(addname);
2311 COPY_STRING_FIELD(newschema);
2316 static AlterOwnerStmt *
2317 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2319 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2321 COPY_SCALAR_FIELD(objectType);
2322 COPY_NODE_FIELD(relation);
2323 COPY_NODE_FIELD(object);
2324 COPY_NODE_FIELD(objarg);
2325 COPY_STRING_FIELD(addname);
2326 COPY_STRING_FIELD(newowner);
2332 _copyRuleStmt(RuleStmt *from)
2334 RuleStmt *newnode = makeNode(RuleStmt);
2336 COPY_NODE_FIELD(relation);
2337 COPY_STRING_FIELD(rulename);
2338 COPY_NODE_FIELD(whereClause);
2339 COPY_SCALAR_FIELD(event);
2340 COPY_SCALAR_FIELD(instead);
2341 COPY_NODE_FIELD(actions);
2342 COPY_SCALAR_FIELD(replace);
2348 _copyNotifyStmt(NotifyStmt *from)
2350 NotifyStmt *newnode = makeNode(NotifyStmt);
2352 COPY_NODE_FIELD(relation);
2358 _copyListenStmt(ListenStmt *from)
2360 ListenStmt *newnode = makeNode(ListenStmt);
2362 COPY_NODE_FIELD(relation);
2367 static UnlistenStmt *
2368 _copyUnlistenStmt(UnlistenStmt *from)
2370 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2372 COPY_NODE_FIELD(relation);
2377 static TransactionStmt *
2378 _copyTransactionStmt(TransactionStmt *from)
2380 TransactionStmt *newnode = makeNode(TransactionStmt);
2382 COPY_SCALAR_FIELD(kind);
2383 COPY_NODE_FIELD(options);
2384 COPY_STRING_FIELD(gid);
2389 static CompositeTypeStmt *
2390 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2392 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2394 COPY_NODE_FIELD(typevar);
2395 COPY_NODE_FIELD(coldeflist);
2400 static CreateEnumStmt *
2401 _copyCreateEnumStmt(CreateEnumStmt *from)
2403 CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
2405 COPY_NODE_FIELD(typename);
2406 COPY_NODE_FIELD(vals);
2412 _copyViewStmt(ViewStmt *from)
2414 ViewStmt *newnode = makeNode(ViewStmt);
2416 COPY_NODE_FIELD(view);
2417 COPY_NODE_FIELD(aliases);
2418 COPY_NODE_FIELD(query);
2419 COPY_SCALAR_FIELD(replace);
2425 _copyLoadStmt(LoadStmt *from)
2427 LoadStmt *newnode = makeNode(LoadStmt);
2429 COPY_STRING_FIELD(filename);
2434 static CreateDomainStmt *
2435 _copyCreateDomainStmt(CreateDomainStmt *from)
2437 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2439 COPY_NODE_FIELD(domainname);
2440 COPY_NODE_FIELD(typename);
2441 COPY_NODE_FIELD(constraints);
2446 static CreateOpClassStmt *
2447 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2449 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2451 COPY_NODE_FIELD(opclassname);
2452 COPY_NODE_FIELD(opfamilyname);
2453 COPY_STRING_FIELD(amname);
2454 COPY_NODE_FIELD(datatype);
2455 COPY_NODE_FIELD(items);
2456 COPY_SCALAR_FIELD(isDefault);
2461 static CreateOpClassItem *
2462 _copyCreateOpClassItem(CreateOpClassItem *from)
2464 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2466 COPY_SCALAR_FIELD(itemtype);
2467 COPY_NODE_FIELD(name);
2468 COPY_NODE_FIELD(args);
2469 COPY_SCALAR_FIELD(number);
2470 COPY_SCALAR_FIELD(recheck);
2471 COPY_NODE_FIELD(class_args);
2472 COPY_NODE_FIELD(storedtype);
2477 static CreateOpFamilyStmt *
2478 _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
2480 CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
2482 COPY_NODE_FIELD(opfamilyname);
2483 COPY_STRING_FIELD(amname);
2488 static AlterOpFamilyStmt *
2489 _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
2491 AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
2493 COPY_NODE_FIELD(opfamilyname);
2494 COPY_STRING_FIELD(amname);
2495 COPY_SCALAR_FIELD(isDrop);
2496 COPY_NODE_FIELD(items);
2501 static CreatedbStmt *
2502 _copyCreatedbStmt(CreatedbStmt *from)
2504 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2506 COPY_STRING_FIELD(dbname);
2507 COPY_NODE_FIELD(options);
2512 static AlterDatabaseStmt *
2513 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2515 AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2517 COPY_STRING_FIELD(dbname);
2518 COPY_NODE_FIELD(options);
2523 static AlterDatabaseSetStmt *
2524 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2526 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2528 COPY_STRING_FIELD(dbname);
2529 COPY_NODE_FIELD(setstmt);
2535 _copyDropdbStmt(DropdbStmt *from)
2537 DropdbStmt *newnode = makeNode(DropdbStmt);
2539 COPY_STRING_FIELD(dbname);
2540 COPY_SCALAR_FIELD(missing_ok);
2546 _copyVacuumStmt(VacuumStmt *from)
2548 VacuumStmt *newnode = makeNode(VacuumStmt);
2550 COPY_SCALAR_FIELD(vacuum);
2551 COPY_SCALAR_FIELD(full);
2552 COPY_SCALAR_FIELD(analyze);
2553 COPY_SCALAR_FIELD(verbose);
2554 COPY_SCALAR_FIELD(freeze_min_age);
2555 COPY_NODE_FIELD(relation);
2556 COPY_NODE_FIELD(va_cols);
2561 static ExplainStmt *
2562 _copyExplainStmt(ExplainStmt *from)
2564 ExplainStmt *newnode = makeNode(ExplainStmt);
2566 COPY_NODE_FIELD(query);
2567 COPY_SCALAR_FIELD(verbose);
2568 COPY_SCALAR_FIELD(analyze);
2573 static CreateSeqStmt *
2574 _copyCreateSeqStmt(CreateSeqStmt *from)
2576 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2578 COPY_NODE_FIELD(sequence);
2579 COPY_NODE_FIELD(options);
2584 static AlterSeqStmt *
2585 _copyAlterSeqStmt(AlterSeqStmt *from)
2587 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2589 COPY_NODE_FIELD(sequence);
2590 COPY_NODE_FIELD(options);
2595 static VariableSetStmt *
2596 _copyVariableSetStmt(VariableSetStmt *from)
2598 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2600 COPY_SCALAR_FIELD(kind);
2601 COPY_STRING_FIELD(name);
2602 COPY_NODE_FIELD(args);
2603 COPY_SCALAR_FIELD(is_local);
2608 static VariableShowStmt *
2609 _copyVariableShowStmt(VariableShowStmt *from)
2611 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2613 COPY_STRING_FIELD(name);
2618 static DiscardStmt *
2619 _copyDiscardStmt(DiscardStmt *from)
2621 DiscardStmt *newnode = makeNode(DiscardStmt);
2623 COPY_SCALAR_FIELD(target);
2628 static CreateTableSpaceStmt *
2629 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2631 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2633 COPY_STRING_FIELD(tablespacename);
2634 COPY_STRING_FIELD(owner);
2635 COPY_STRING_FIELD(location);
2640 static DropTableSpaceStmt *
2641 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2643 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2645 COPY_STRING_FIELD(tablespacename);
2646 COPY_SCALAR_FIELD(missing_ok);
2651 static CreateTrigStmt *
2652 _copyCreateTrigStmt(CreateTrigStmt *from)
2654 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2656 COPY_STRING_FIELD(trigname);
2657 COPY_NODE_FIELD(relation);
2658 COPY_NODE_FIELD(funcname);
2659 COPY_NODE_FIELD(args);
2660 COPY_SCALAR_FIELD(before);
2661 COPY_SCALAR_FIELD(row);
2662 strcpy(newnode->actions, from->actions); /* in-line string field */
2663 COPY_SCALAR_FIELD(isconstraint);
2664 COPY_SCALAR_FIELD(deferrable);
2665 COPY_SCALAR_FIELD(initdeferred);
2666 COPY_NODE_FIELD(constrrel);
2671 static DropPropertyStmt *
2672 _copyDropPropertyStmt(DropPropertyStmt *from)
2674 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2676 COPY_NODE_FIELD(relation);
2677 COPY_STRING_FIELD(property);
2678 COPY_SCALAR_FIELD(removeType);
2679 COPY_SCALAR_FIELD(behavior);
2680 COPY_SCALAR_FIELD(missing_ok);
2685 static CreatePLangStmt *
2686 _copyCreatePLangStmt(CreatePLangStmt *from)
2688 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2690 COPY_STRING_FIELD(plname);
2691 COPY_NODE_FIELD(plhandler);
2692 COPY_NODE_FIELD(plvalidator);
2693 COPY_SCALAR_FIELD(pltrusted);
2698 static DropPLangStmt *
2699 _copyDropPLangStmt(DropPLangStmt *from)
2701 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2703 COPY_STRING_FIELD(plname);
2704 COPY_SCALAR_FIELD(behavior);
2705 COPY_SCALAR_FIELD(missing_ok);
2710 static CreateRoleStmt *
2711 _copyCreateRoleStmt(CreateRoleStmt *from)
2713 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2715 COPY_SCALAR_FIELD(stmt_type);
2716 COPY_STRING_FIELD(role);
2717 COPY_NODE_FIELD(options);
2722 static AlterRoleStmt *
2723 _copyAlterRoleStmt(AlterRoleStmt *from)
2725 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2727 COPY_STRING_FIELD(role);
2728 COPY_NODE_FIELD(options);
2729 COPY_SCALAR_FIELD(action);
2734 static AlterRoleSetStmt *
2735 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2737 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2739 COPY_STRING_FIELD(role);
2740 COPY_NODE_FIELD(setstmt);
2745 static DropRoleStmt *
2746 _copyDropRoleStmt(DropRoleStmt *from)
2748 DropRoleStmt *newnode = makeNode(DropRoleStmt);
2750 COPY_NODE_FIELD(roles);
2751 COPY_SCALAR_FIELD(missing_ok);
2757 _copyLockStmt(LockStmt *from)
2759 LockStmt *newnode = makeNode(LockStmt);
2761 COPY_NODE_FIELD(relations);
2762 COPY_SCALAR_FIELD(mode);
2763 COPY_SCALAR_FIELD(nowait);
2768 static ConstraintsSetStmt *
2769 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2771 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2773 COPY_NODE_FIELD(constraints);
2774 COPY_SCALAR_FIELD(deferred);
2779 static ReindexStmt *
2780 _copyReindexStmt(ReindexStmt *from)
2782 ReindexStmt *newnode = makeNode(ReindexStmt);
2784 COPY_SCALAR_FIELD(kind);
2785 COPY_NODE_FIELD(relation);
2786 COPY_STRING_FIELD(name);
2787 COPY_SCALAR_FIELD(do_system);
2788 COPY_SCALAR_FIELD(do_user);
2793 static CreateSchemaStmt *
2794 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2796 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2798 COPY_STRING_FIELD(schemaname);
2799 COPY_STRING_FIELD(authid);
2800 COPY_NODE_FIELD(schemaElts);
2805 static CreateConversionStmt *
2806 _copyCreateConversionStmt(CreateConversionStmt *from)
2808 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2810 COPY_NODE_FIELD(conversion_name);
2811 COPY_STRING_FIELD(for_encoding_name);
2812 COPY_STRING_FIELD(to_encoding_name);
2813 COPY_NODE_FIELD(func_name);
2814 COPY_SCALAR_FIELD(def);
2819 static CreateCastStmt *
2820 _copyCreateCastStmt(CreateCastStmt *from)
2822 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2824 COPY_NODE_FIELD(sourcetype);
2825 COPY_NODE_FIELD(targettype);
2826 COPY_NODE_FIELD(func);
2827 COPY_SCALAR_FIELD(context);
2832 static DropCastStmt *
2833 _copyDropCastStmt(DropCastStmt *from)
2835 DropCastStmt *newnode = makeNode(DropCastStmt);
2837 COPY_NODE_FIELD(sourcetype);
2838 COPY_NODE_FIELD(targettype);
2839 COPY_SCALAR_FIELD(behavior);
2840 COPY_SCALAR_FIELD(missing_ok);
2845 static PrepareStmt *
2846 _copyPrepareStmt(PrepareStmt *from)
2848 PrepareStmt *newnode = makeNode(PrepareStmt);
2850 COPY_STRING_FIELD(name);
2851 COPY_NODE_FIELD(argtypes);
2852 COPY_NODE_FIELD(query);
2857 static ExecuteStmt *
2858 _copyExecuteStmt(ExecuteStmt *from)
2860 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2862 COPY_STRING_FIELD(name);
2863 COPY_NODE_FIELD(into);
2864 COPY_NODE_FIELD(params);
2869 static DeallocateStmt *
2870 _copyDeallocateStmt(DeallocateStmt *from)
2872 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2874 COPY_STRING_FIELD(name);
2879 static DropOwnedStmt *
2880 _copyDropOwnedStmt(DropOwnedStmt *from)
2882 DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
2884 COPY_NODE_FIELD(roles);
2885 COPY_SCALAR_FIELD(behavior);
2890 static ReassignOwnedStmt *
2891 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
2893 ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
2895 COPY_NODE_FIELD(roles);
2896 COPY_SCALAR_FIELD(newrole);
2901 /* ****************************************************************
2902 * pg_list.h copy functions
2903 * ****************************************************************
2907 * Perform a deep copy of the specified list, using copyObject(). The
2908 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2909 * need deep copies, so they should be copied via list_copy()
2911 #define COPY_NODE_CELL(new, old) \
2912 (new) = (ListCell *) palloc(sizeof(ListCell)); \
2913 lfirst(new) = copyObject(lfirst(old));
2916 _copyList(List *from)
2922 Assert(list_length(from) >= 1);
2924 new = makeNode(List);
2925 new->length = from->length;
2927 COPY_NODE_CELL(new->head, from->head);
2928 prev_new = new->head;
2929 curr_old = lnext(from->head);
2933 COPY_NODE_CELL(prev_new->next, curr_old);
2934 prev_new = prev_new->next;
2935 curr_old = curr_old->next;
2937 prev_new->next = NULL;
2938 new->tail = prev_new;
2943 /* ****************************************************************
2944 * value.h copy functions
2945 * ****************************************************************
2948 _copyValue(Value *from)
2950 Value *newnode = makeNode(Value);
2952 /* See also _copyAConst when changing this code! */
2954 COPY_SCALAR_FIELD(type);
2958 COPY_SCALAR_FIELD(val.ival);
2963 COPY_STRING_FIELD(val.str);
2969 elog(ERROR, "unrecognized node type: %d",
2979 * Create a copy of a Node tree or list. This is a "deep" copy: all
2980 * substructure is copied too, recursively.
2983 copyObject(void *from)
2990 switch (nodeTag(from))
2996 retval = _copyPlannedStmt(from);
2999 retval = _copyPlan(from);
3002 retval = _copyResult(from);
3005 retval = _copyAppend(from);
3008 retval = _copyBitmapAnd(from);
3011 retval = _copyBitmapOr(from);
3014 retval = _copyScan(from);
3017 retval = _copySeqScan(from);
3020 retval = _copyIndexScan(from);
3022 case T_BitmapIndexScan:
3023 retval = _copyBitmapIndexScan(from);
3025 case T_BitmapHeapScan:
3026 retval = _copyBitmapHeapScan(from);
3029 retval = _copyTidScan(from);
3031 case T_SubqueryScan:
3032 retval = _copySubqueryScan(from);
3034 case T_FunctionScan:
3035 retval = _copyFunctionScan(from);
3038 retval = _copyValuesScan(from);
3041 retval = _copyJoin(from);
3044 retval = _copyNestLoop(from);
3047 retval = _copyMergeJoin(from);
3050 retval = _copyHashJoin(from);
3053 retval = _copyMaterial(from);
3056 retval = _copySort(from);
3059 retval = _copyGroup(from);
3062 retval = _copyAgg(from);
3065 retval = _copyUnique(from);
3068 retval = _copyHash(from);
3071 retval = _copySetOp(from);
3074 retval = _copyLimit(from);
3081 retval = _copyAlias(from);
3084 retval = _copyRangeVar(from);
3087 retval = _copyIntoClause(from);
3090 retval = _copyVar(from);
3093 retval = _copyConst(from);
3096 retval = _copyParam(from);
3099 retval = _copyAggref(from);
3102 retval = _copyArrayRef(from);
3105 retval = _copyFuncExpr(from);
3108 retval = _copyOpExpr(from);
3110 case T_DistinctExpr:
3111 retval = _copyDistinctExpr(from);
3113 case T_ScalarArrayOpExpr:
3114 retval = _copyScalarArrayOpExpr(from);
3117 retval = _copyBoolExpr(from);
3120 retval = _copySubLink(from);
3123 retval = _copySubPlan(from);
3126 retval = _copyFieldSelect(from);
3129 retval = _copyFieldStore(from);
3132 retval = _copyRelabelType(from);
3135 retval = _copyCoerceViaIO(from);
3137 case T_ArrayCoerceExpr:
3138 retval = _copyArrayCoerceExpr(from);
3140 case T_ConvertRowtypeExpr:
3141 retval = _copyConvertRowtypeExpr(from);
3144 retval = _copyCaseExpr(from);
3147 retval = _copyCaseWhen(from);
3149 case T_CaseTestExpr:
3150 retval = _copyCaseTestExpr(from);
3153 retval = _copyArrayExpr(from);
3156 retval = _copyRowExpr(from);
3158 case T_RowCompareExpr:
3159 retval = _copyRowCompareExpr(from);
3161 case T_CoalesceExpr:
3162 retval = _copyCoalesceExpr(from);
3165 retval = _copyMinMaxExpr(from);
3168 retval = _copyXmlExpr(from);
3171 retval = _copyNullIfExpr(from);
3174 retval = _copyNullTest(from);
3177 retval = _copyBooleanTest(from);
3179 case T_CoerceToDomain:
3180 retval = _copyCoerceToDomain(from);
3182 case T_CoerceToDomainValue:
3183 retval = _copyCoerceToDomainValue(from);
3185 case T_SetToDefault:
3186 retval = _copySetToDefault(from);
3188 case T_CurrentOfExpr:
3189 retval = _copyCurrentOfExpr(from);
3192 retval = _copyTargetEntry(from);
3195 retval = _copyRangeTblRef(from);
3198 retval = _copyJoinExpr(from);
3201 retval = _copyFromExpr(from);
3208 retval = _copyPathKey(from);
3210 case T_RestrictInfo:
3211 retval = _copyRestrictInfo(from);
3213 case T_OuterJoinInfo:
3214 retval = _copyOuterJoinInfo(from);
3216 case T_InClauseInfo:
3217 retval = _copyInClauseInfo(from);
3219 case T_AppendRelInfo:
3220 retval = _copyAppendRelInfo(from);
3231 retval = _copyValue(from);
3238 retval = _copyList(from);
3242 * Lists of integers and OIDs don't need to be deep-copied, so we
3243 * perform a shallow copy via list_copy()
3247 retval = list_copy(from);
3254 retval = _copyQuery(from);
3257 retval = _copyInsertStmt(from);
3260 retval = _copyDeleteStmt(from);
3263 retval = _copyUpdateStmt(from);
3266 retval = _copySelectStmt(from);
3268 case T_SetOperationStmt:
3269 retval = _copySetOperationStmt(from);
3271 case T_AlterTableStmt:
3272 retval = _copyAlterTableStmt(from);
3274 case T_AlterTableCmd:
3275 retval = _copyAlterTableCmd(from);
3277 case T_AlterDomainStmt:
3278 retval = _copyAlterDomainStmt(from);
3281 retval = _copyGrantStmt(from);
3283 case T_GrantRoleStmt:
3284 retval = _copyGrantRoleStmt(from);
3286 case T_DeclareCursorStmt:
3287 retval = _copyDeclareCursorStmt(from);
3289 case T_ClosePortalStmt:
3290 retval = _copyClosePortalStmt(from);
3293 retval = _copyClusterStmt(from);
3296 retval = _copyCopyStmt(from);
3299 retval = _copyCreateStmt(from);
3302 retval = _copyInhRelation(from);
3305 retval = _copyDefineStmt(from);
3308 retval = _copyDropStmt(from);
3310 case T_TruncateStmt:
3311 retval = _copyTruncateStmt(from);
3314 retval = _copyCommentStmt(from);
3317 retval = _copyFetchStmt(from);
3320 retval = _copyIndexStmt(from);
3322 case T_CreateFunctionStmt:
3323 retval = _copyCreateFunctionStmt(from);
3325 case T_FunctionParameter:
3326 retval = _copyFunctionParameter(from);
3328 case T_AlterFunctionStmt:
3329 retval = _copyAlterFunctionStmt(from);
3331 case T_RemoveFuncStmt:
3332 retval = _copyRemoveFuncStmt(from);
3334 case T_RemoveOpClassStmt:
3335 retval = _copyRemoveOpClassStmt(from);
3337 case T_RemoveOpFamilyStmt:
3338 retval = _copyRemoveOpFamilyStmt(from);
3341 retval = _copyRenameStmt(from);
3343 case T_AlterObjectSchemaStmt:
3344 retval = _copyAlterObjectSchemaStmt(from);
3346 case T_AlterOwnerStmt:
3347 retval = _copyAlterOwnerStmt(from);
3350 retval = _copyRuleStmt(from);
3353 retval = _copyNotifyStmt(from);
3356 retval = _copyListenStmt(from);
3358 case T_UnlistenStmt:
3359 retval = _copyUnlistenStmt(from);
3361 case T_TransactionStmt:
3362 retval = _copyTransactionStmt(from);
3364 case T_CompositeTypeStmt:
3365 retval = _copyCompositeTypeStmt(from);
3367 case T_CreateEnumStmt:
3368 retval = _copyCreateEnumStmt(from);
3371 retval = _copyViewStmt(from);
3374 retval = _copyLoadStmt(from);
3376 case T_CreateDomainStmt:
3377 retval = _copyCreateDomainStmt(from);
3379 case T_CreateOpClassStmt:
3380 retval = _copyCreateOpClassStmt(from);
3382 case T_CreateOpClassItem:
3383 retval = _copyCreateOpClassItem(from);
3385 case T_CreateOpFamilyStmt:
3386 retval = _copyCreateOpFamilyStmt(from);
3388 case T_AlterOpFamilyStmt:
3389 retval = _copyAlterOpFamilyStmt(from);
3391 case T_CreatedbStmt:
3392 retval = _copyCreatedbStmt(from);
3394 case T_AlterDatabaseStmt:
3395 retval = _copyAlterDatabaseStmt(from);
3397 case T_AlterDatabaseSetStmt:
3398 retval = _copyAlterDatabaseSetStmt(from);
3401 retval = _copyDropdbStmt(from);
3404 retval = _copyVacuumStmt(from);
3407 retval = _copyExplainStmt(from);
3409 case T_CreateSeqStmt:
3410 retval = _copyCreateSeqStmt(from);
3412 case T_AlterSeqStmt:
3413 retval = _copyAlterSeqStmt(from);
3415 case T_VariableSetStmt:
3416 retval = _copyVariableSetStmt(from);
3418 case T_VariableShowStmt:
3419 retval = _copyVariableShowStmt(from);
3422 retval = _copyDiscardStmt(from);
3424 case T_CreateTableSpaceStmt:
3425 retval = _copyCreateTableSpaceStmt(from);
3427 case T_DropTableSpaceStmt:
3428 retval = _copyDropTableSpaceStmt(from);
3430 case T_CreateTrigStmt:
3431 retval = _copyCreateTrigStmt(from);
3433 case T_DropPropertyStmt:
3434 retval = _copyDropPropertyStmt(from);
3436 case T_CreatePLangStmt:
3437 retval = _copyCreatePLangStmt(from);
3439 case T_DropPLangStmt:
3440 retval = _copyDropPLangStmt(from);
3442 case T_CreateRoleStmt:
3443 retval = _copyCreateRoleStmt(from);
3445 case T_AlterRoleStmt:
3446 retval = _copyAlterRoleStmt(from);
3448 case T_AlterRoleSetStmt:
3449 retval = _copyAlterRoleSetStmt(from);
3451 case T_DropRoleStmt:
3452 retval = _copyDropRoleStmt(from);
3455 retval = _copyLockStmt(from);
3457 case T_ConstraintsSetStmt:
3458 retval = _copyConstraintsSetStmt(from);
3461 retval = _copyReindexStmt(from);
3463 case T_CheckPointStmt:
3464 retval = (void *) makeNode(CheckPointStmt);
3466 case T_CreateSchemaStmt:
3467 retval = _copyCreateSchemaStmt(from);
3469 case T_CreateConversionStmt:
3470 retval = _copyCreateConversionStmt(from);
3472 case T_CreateCastStmt:
3473 retval = _copyCreateCastStmt(from);
3475 case T_DropCastStmt:
3476 retval = _copyDropCastStmt(from);
3479 retval = _copyPrepareStmt(from);
3482 retval = _copyExecuteStmt(from);
3484 case T_DeallocateStmt:
3485 retval = _copyDeallocateStmt(from);
3487 case T_DropOwnedStmt:
3488 retval = _copyDropOwnedStmt(from);
3490 case T_ReassignOwnedStmt:
3491 retval = _copyReassignOwnedStmt(from);
3495 retval = _copyAExpr(from);
3498 retval = _copyColumnRef(from);
3501 retval = _copyParamRef(from);
3504 retval = _copyAConst(from);
3507 retval = _copyFuncCall(from);
3510 retval = _copyAIndices(from);
3512 case T_A_Indirection:
3513 retval = _copyA_Indirection(from);
3516 retval = _copyResTarget(from);
3519 retval = _copyTypeCast(from);
3522 retval = _copySortBy(from);
3524 case T_RangeSubselect:
3525 retval = _copyRangeSubselect(from);
3527 case T_RangeFunction:
3528 retval = _copyRangeFunction(from);
3531 retval = _copyTypeName(from);
3534 retval = _copyIndexElem(from);
3537 retval = _copyColumnDef(from);
3540 retval = _copyConstraint(from);
3543 retval = _copyDefElem(from);
3545 case T_LockingClause:
3546 retval = _copyLockingClause(from);
3548 case T_RangeTblEntry:
3549 retval = _copyRangeTblEntry(from);
3552 retval = _copySortClause(from);
3555 retval = _copyGroupClause(from);
3557 case T_RowMarkClause:
3558 retval = _copyRowMarkClause(from);
3560 case T_FkConstraint:
3561 retval = _copyFkConstraint(from);
3564 retval = _copyPrivGrantee(from);
3566 case T_FuncWithArgs:
3567 retval = _copyFuncWithArgs(from);
3569 case T_XmlSerialize:
3570 retval = _copyXmlSerialize(from);
3574 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3575 retval = from; /* keep compiler quiet */