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-2008, 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.395 2008/07/16 01:30:22 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_SCALAR_FIELD(indexorderdir);
288 * _copyBitmapIndexScan
290 static BitmapIndexScan *
291 _copyBitmapIndexScan(BitmapIndexScan *from)
293 BitmapIndexScan *newnode = makeNode(BitmapIndexScan);
296 * copy node superclass fields
298 CopyScanFields((Scan *) from, (Scan *) newnode);
301 * copy remainder of node
303 COPY_SCALAR_FIELD(indexid);
304 COPY_NODE_FIELD(indexqual);
305 COPY_NODE_FIELD(indexqualorig);
311 * _copyBitmapHeapScan
313 static BitmapHeapScan *
314 _copyBitmapHeapScan(BitmapHeapScan *from)
316 BitmapHeapScan *newnode = makeNode(BitmapHeapScan);
319 * copy node superclass fields
321 CopyScanFields((Scan *) from, (Scan *) newnode);
324 * copy remainder of node
326 COPY_NODE_FIELD(bitmapqualorig);
335 _copyTidScan(TidScan *from)
337 TidScan *newnode = makeNode(TidScan);
340 * copy node superclass fields
342 CopyScanFields((Scan *) from, (Scan *) newnode);
345 * copy remainder of node
347 COPY_NODE_FIELD(tidquals);
355 static SubqueryScan *
356 _copySubqueryScan(SubqueryScan *from)
358 SubqueryScan *newnode = makeNode(SubqueryScan);
361 * copy node superclass fields
363 CopyScanFields((Scan *) from, (Scan *) newnode);
366 * copy remainder of node
368 COPY_NODE_FIELD(subplan);
369 COPY_NODE_FIELD(subrtable);
377 static FunctionScan *
378 _copyFunctionScan(FunctionScan *from)
380 FunctionScan *newnode = makeNode(FunctionScan);
383 * copy node superclass fields
385 CopyScanFields((Scan *) from, (Scan *) newnode);
388 * copy remainder of node
390 COPY_NODE_FIELD(funcexpr);
391 COPY_NODE_FIELD(funccolnames);
392 COPY_NODE_FIELD(funccoltypes);
393 COPY_NODE_FIELD(funccoltypmods);
402 _copyValuesScan(ValuesScan *from)
404 ValuesScan *newnode = makeNode(ValuesScan);
407 * copy node superclass fields
409 CopyScanFields((Scan *) from, (Scan *) newnode);
412 * copy remainder of node
414 COPY_NODE_FIELD(values_lists);
422 * This function copies the fields of the Join node. It is used by
423 * all the copy functions for classes which inherit from Join.
426 CopyJoinFields(Join *from, Join *newnode)
428 CopyPlanFields((Plan *) from, (Plan *) newnode);
430 COPY_SCALAR_FIELD(jointype);
431 COPY_NODE_FIELD(joinqual);
439 _copyJoin(Join *from)
441 Join *newnode = makeNode(Join);
444 * copy node superclass fields
446 CopyJoinFields(from, newnode);
456 _copyNestLoop(NestLoop *from)
458 NestLoop *newnode = makeNode(NestLoop);
461 * copy node superclass fields
463 CopyJoinFields((Join *) from, (Join *) newnode);
473 _copyMergeJoin(MergeJoin *from)
475 MergeJoin *newnode = makeNode(MergeJoin);
479 * copy node superclass fields
481 CopyJoinFields((Join *) from, (Join *) newnode);
484 * copy remainder of node
486 COPY_NODE_FIELD(mergeclauses);
487 numCols = list_length(from->mergeclauses);
488 COPY_POINTER_FIELD(mergeFamilies, numCols * sizeof(Oid));
489 COPY_POINTER_FIELD(mergeStrategies, numCols * sizeof(int));
490 COPY_POINTER_FIELD(mergeNullsFirst, numCols * sizeof(bool));
499 _copyHashJoin(HashJoin *from)
501 HashJoin *newnode = makeNode(HashJoin);
504 * copy node superclass fields
506 CopyJoinFields((Join *) from, (Join *) newnode);
509 * copy remainder of node
511 COPY_NODE_FIELD(hashclauses);
521 _copyMaterial(Material *from)
523 Material *newnode = makeNode(Material);
526 * copy node superclass fields
528 CopyPlanFields((Plan *) from, (Plan *) newnode);
538 _copySort(Sort *from)
540 Sort *newnode = makeNode(Sort);
543 * copy node superclass fields
545 CopyPlanFields((Plan *) from, (Plan *) newnode);
547 COPY_SCALAR_FIELD(numCols);
548 COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
549 COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
550 COPY_POINTER_FIELD(nullsFirst, from->numCols * sizeof(bool));
560 _copyGroup(Group *from)
562 Group *newnode = makeNode(Group);
564 CopyPlanFields((Plan *) from, (Plan *) newnode);
566 COPY_SCALAR_FIELD(numCols);
567 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
568 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
579 Agg *newnode = makeNode(Agg);
581 CopyPlanFields((Plan *) from, (Plan *) newnode);
583 COPY_SCALAR_FIELD(aggstrategy);
584 COPY_SCALAR_FIELD(numCols);
585 if (from->numCols > 0)
587 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
588 COPY_POINTER_FIELD(grpOperators, from->numCols * sizeof(Oid));
590 COPY_SCALAR_FIELD(numGroups);
599 _copyUnique(Unique *from)
601 Unique *newnode = makeNode(Unique);
604 * copy node superclass fields
606 CopyPlanFields((Plan *) from, (Plan *) newnode);
609 * copy remainder of node
611 COPY_SCALAR_FIELD(numCols);
612 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
613 COPY_POINTER_FIELD(uniqOperators, from->numCols * sizeof(Oid));
622 _copyHash(Hash *from)
624 Hash *newnode = makeNode(Hash);
627 * copy node superclass fields
629 CopyPlanFields((Plan *) from, (Plan *) newnode);
632 * copy remainder of node
642 _copySetOp(SetOp *from)
644 SetOp *newnode = makeNode(SetOp);
647 * copy node superclass fields
649 CopyPlanFields((Plan *) from, (Plan *) newnode);
652 * copy remainder of node
654 COPY_SCALAR_FIELD(cmd);
655 COPY_SCALAR_FIELD(numCols);
656 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
657 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
658 COPY_SCALAR_FIELD(flagColIdx);
667 _copyLimit(Limit *from)
669 Limit *newnode = makeNode(Limit);
672 * copy node superclass fields
674 CopyPlanFields((Plan *) from, (Plan *) newnode);
677 * copy remainder of node
679 COPY_NODE_FIELD(limitOffset);
680 COPY_NODE_FIELD(limitCount);
685 /* ****************************************************************
686 * primnodes.h copy functions
687 * ****************************************************************
694 _copyAlias(Alias *from)
696 Alias *newnode = makeNode(Alias);
698 COPY_STRING_FIELD(aliasname);
699 COPY_NODE_FIELD(colnames);
708 _copyRangeVar(RangeVar *from)
710 RangeVar *newnode = makeNode(RangeVar);
712 COPY_STRING_FIELD(catalogname);
713 COPY_STRING_FIELD(schemaname);
714 COPY_STRING_FIELD(relname);
715 COPY_SCALAR_FIELD(inhOpt);
716 COPY_SCALAR_FIELD(istemp);
717 COPY_NODE_FIELD(alias);
726 _copyIntoClause(IntoClause *from)
728 IntoClause *newnode = makeNode(IntoClause);
730 COPY_NODE_FIELD(rel);
731 COPY_NODE_FIELD(colNames);
732 COPY_NODE_FIELD(options);
733 COPY_SCALAR_FIELD(onCommit);
734 COPY_STRING_FIELD(tableSpaceName);
740 * We don't need a _copyExpr because Expr is an abstract supertype which
741 * should never actually get instantiated. Also, since it has no common
742 * fields except NodeTag, there's no need for a helper routine to factor
743 * out copying the common fields...
752 Var *newnode = makeNode(Var);
754 COPY_SCALAR_FIELD(varno);
755 COPY_SCALAR_FIELD(varattno);
756 COPY_SCALAR_FIELD(vartype);
757 COPY_SCALAR_FIELD(vartypmod);
758 COPY_SCALAR_FIELD(varlevelsup);
759 COPY_SCALAR_FIELD(varnoold);
760 COPY_SCALAR_FIELD(varoattno);
769 _copyConst(Const *from)
771 Const *newnode = makeNode(Const);
773 COPY_SCALAR_FIELD(consttype);
774 COPY_SCALAR_FIELD(consttypmod);
775 COPY_SCALAR_FIELD(constlen);
777 if (from->constbyval || from->constisnull)
780 * passed by value so just copy the datum. Also, don't try to copy
781 * struct when value is null!
783 newnode->constvalue = from->constvalue;
788 * passed by reference. We need a palloc'd copy.
790 newnode->constvalue = datumCopy(from->constvalue,
795 COPY_SCALAR_FIELD(constisnull);
796 COPY_SCALAR_FIELD(constbyval);
805 _copyParam(Param *from)
807 Param *newnode = makeNode(Param);
809 COPY_SCALAR_FIELD(paramkind);
810 COPY_SCALAR_FIELD(paramid);
811 COPY_SCALAR_FIELD(paramtype);
812 COPY_SCALAR_FIELD(paramtypmod);
821 _copyAggref(Aggref *from)
823 Aggref *newnode = makeNode(Aggref);
825 COPY_SCALAR_FIELD(aggfnoid);
826 COPY_SCALAR_FIELD(aggtype);
827 COPY_NODE_FIELD(args);
828 COPY_SCALAR_FIELD(agglevelsup);
829 COPY_SCALAR_FIELD(aggstar);
830 COPY_SCALAR_FIELD(aggdistinct);
839 _copyArrayRef(ArrayRef *from)
841 ArrayRef *newnode = makeNode(ArrayRef);
843 COPY_SCALAR_FIELD(refarraytype);
844 COPY_SCALAR_FIELD(refelemtype);
845 COPY_SCALAR_FIELD(reftypmod);
846 COPY_NODE_FIELD(refupperindexpr);
847 COPY_NODE_FIELD(reflowerindexpr);
848 COPY_NODE_FIELD(refexpr);
849 COPY_NODE_FIELD(refassgnexpr);
858 _copyFuncExpr(FuncExpr *from)
860 FuncExpr *newnode = makeNode(FuncExpr);
862 COPY_SCALAR_FIELD(funcid);
863 COPY_SCALAR_FIELD(funcresulttype);
864 COPY_SCALAR_FIELD(funcretset);
865 COPY_SCALAR_FIELD(funcformat);
866 COPY_NODE_FIELD(args);
875 _copyOpExpr(OpExpr *from)
877 OpExpr *newnode = makeNode(OpExpr);
879 COPY_SCALAR_FIELD(opno);
880 COPY_SCALAR_FIELD(opfuncid);
881 COPY_SCALAR_FIELD(opresulttype);
882 COPY_SCALAR_FIELD(opretset);
883 COPY_NODE_FIELD(args);
889 * _copyDistinctExpr (same as OpExpr)
891 static DistinctExpr *
892 _copyDistinctExpr(DistinctExpr *from)
894 DistinctExpr *newnode = makeNode(DistinctExpr);
896 COPY_SCALAR_FIELD(opno);
897 COPY_SCALAR_FIELD(opfuncid);
898 COPY_SCALAR_FIELD(opresulttype);
899 COPY_SCALAR_FIELD(opretset);
900 COPY_NODE_FIELD(args);
906 * _copyScalarArrayOpExpr
908 static ScalarArrayOpExpr *
909 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
911 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
913 COPY_SCALAR_FIELD(opno);
914 COPY_SCALAR_FIELD(opfuncid);
915 COPY_SCALAR_FIELD(useOr);
916 COPY_NODE_FIELD(args);
925 _copyBoolExpr(BoolExpr *from)
927 BoolExpr *newnode = makeNode(BoolExpr);
929 COPY_SCALAR_FIELD(boolop);
930 COPY_NODE_FIELD(args);
939 _copySubLink(SubLink *from)
941 SubLink *newnode = makeNode(SubLink);
943 COPY_SCALAR_FIELD(subLinkType);
944 COPY_NODE_FIELD(testexpr);
945 COPY_NODE_FIELD(operName);
946 COPY_NODE_FIELD(subselect);
955 _copySubPlan(SubPlan *from)
957 SubPlan *newnode = makeNode(SubPlan);
959 COPY_SCALAR_FIELD(subLinkType);
960 COPY_NODE_FIELD(testexpr);
961 COPY_NODE_FIELD(paramIds);
962 COPY_SCALAR_FIELD(plan_id);
963 COPY_SCALAR_FIELD(firstColType);
964 COPY_SCALAR_FIELD(useHashTable);
965 COPY_SCALAR_FIELD(unknownEqFalse);
966 COPY_NODE_FIELD(setParam);
967 COPY_NODE_FIELD(parParam);
968 COPY_NODE_FIELD(args);
977 _copyFieldSelect(FieldSelect *from)
979 FieldSelect *newnode = makeNode(FieldSelect);
981 COPY_NODE_FIELD(arg);
982 COPY_SCALAR_FIELD(fieldnum);
983 COPY_SCALAR_FIELD(resulttype);
984 COPY_SCALAR_FIELD(resulttypmod);
993 _copyFieldStore(FieldStore *from)
995 FieldStore *newnode = makeNode(FieldStore);
997 COPY_NODE_FIELD(arg);
998 COPY_NODE_FIELD(newvals);
999 COPY_NODE_FIELD(fieldnums);
1000 COPY_SCALAR_FIELD(resulttype);
1008 static RelabelType *
1009 _copyRelabelType(RelabelType *from)
1011 RelabelType *newnode = makeNode(RelabelType);
1013 COPY_NODE_FIELD(arg);
1014 COPY_SCALAR_FIELD(resulttype);
1015 COPY_SCALAR_FIELD(resulttypmod);
1016 COPY_SCALAR_FIELD(relabelformat);
1024 static CoerceViaIO *
1025 _copyCoerceViaIO(CoerceViaIO *from)
1027 CoerceViaIO *newnode = makeNode(CoerceViaIO);
1029 COPY_NODE_FIELD(arg);
1030 COPY_SCALAR_FIELD(resulttype);
1031 COPY_SCALAR_FIELD(coerceformat);
1037 * _copyArrayCoerceExpr
1039 static ArrayCoerceExpr *
1040 _copyArrayCoerceExpr(ArrayCoerceExpr *from)
1042 ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1044 COPY_NODE_FIELD(arg);
1045 COPY_SCALAR_FIELD(elemfuncid);
1046 COPY_SCALAR_FIELD(resulttype);
1047 COPY_SCALAR_FIELD(resulttypmod);
1048 COPY_SCALAR_FIELD(isExplicit);
1049 COPY_SCALAR_FIELD(coerceformat);
1055 * _copyConvertRowtypeExpr
1057 static ConvertRowtypeExpr *
1058 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
1060 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1062 COPY_NODE_FIELD(arg);
1063 COPY_SCALAR_FIELD(resulttype);
1064 COPY_SCALAR_FIELD(convertformat);
1073 _copyCaseExpr(CaseExpr *from)
1075 CaseExpr *newnode = makeNode(CaseExpr);
1077 COPY_SCALAR_FIELD(casetype);
1078 COPY_NODE_FIELD(arg);
1079 COPY_NODE_FIELD(args);
1080 COPY_NODE_FIELD(defresult);
1089 _copyCaseWhen(CaseWhen *from)
1091 CaseWhen *newnode = makeNode(CaseWhen);
1093 COPY_NODE_FIELD(expr);
1094 COPY_NODE_FIELD(result);
1102 static CaseTestExpr *
1103 _copyCaseTestExpr(CaseTestExpr *from)
1105 CaseTestExpr *newnode = makeNode(CaseTestExpr);
1107 COPY_SCALAR_FIELD(typeId);
1108 COPY_SCALAR_FIELD(typeMod);
1117 _copyArrayExpr(ArrayExpr *from)
1119 ArrayExpr *newnode = makeNode(ArrayExpr);
1121 COPY_SCALAR_FIELD(array_typeid);
1122 COPY_SCALAR_FIELD(element_typeid);
1123 COPY_NODE_FIELD(elements);
1124 COPY_SCALAR_FIELD(multidims);
1133 _copyRowExpr(RowExpr *from)
1135 RowExpr *newnode = makeNode(RowExpr);
1137 COPY_NODE_FIELD(args);
1138 COPY_SCALAR_FIELD(row_typeid);
1139 COPY_SCALAR_FIELD(row_format);
1145 * _copyRowCompareExpr
1147 static RowCompareExpr *
1148 _copyRowCompareExpr(RowCompareExpr *from)
1150 RowCompareExpr *newnode = makeNode(RowCompareExpr);
1152 COPY_SCALAR_FIELD(rctype);
1153 COPY_NODE_FIELD(opnos);
1154 COPY_NODE_FIELD(opfamilies);
1155 COPY_NODE_FIELD(largs);
1156 COPY_NODE_FIELD(rargs);
1164 static CoalesceExpr *
1165 _copyCoalesceExpr(CoalesceExpr *from)
1167 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1169 COPY_SCALAR_FIELD(coalescetype);
1170 COPY_NODE_FIELD(args);
1179 _copyMinMaxExpr(MinMaxExpr *from)
1181 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1183 COPY_SCALAR_FIELD(minmaxtype);
1184 COPY_SCALAR_FIELD(op);
1185 COPY_NODE_FIELD(args);
1194 _copyXmlExpr(XmlExpr *from)
1196 XmlExpr *newnode = makeNode(XmlExpr);
1198 COPY_SCALAR_FIELD(op);
1199 COPY_STRING_FIELD(name);
1200 COPY_NODE_FIELD(named_args);
1201 COPY_NODE_FIELD(arg_names);
1202 COPY_NODE_FIELD(args);
1203 COPY_SCALAR_FIELD(xmloption);
1204 COPY_SCALAR_FIELD(type);
1205 COPY_SCALAR_FIELD(typmod);
1211 * _copyNullIfExpr (same as OpExpr)
1214 _copyNullIfExpr(NullIfExpr *from)
1216 NullIfExpr *newnode = makeNode(NullIfExpr);
1218 COPY_SCALAR_FIELD(opno);
1219 COPY_SCALAR_FIELD(opfuncid);
1220 COPY_SCALAR_FIELD(opresulttype);
1221 COPY_SCALAR_FIELD(opretset);
1222 COPY_NODE_FIELD(args);
1231 _copyNullTest(NullTest *from)
1233 NullTest *newnode = makeNode(NullTest);
1235 COPY_NODE_FIELD(arg);
1236 COPY_SCALAR_FIELD(nulltesttype);
1244 static BooleanTest *
1245 _copyBooleanTest(BooleanTest *from)
1247 BooleanTest *newnode = makeNode(BooleanTest);
1249 COPY_NODE_FIELD(arg);
1250 COPY_SCALAR_FIELD(booltesttype);
1256 * _copyCoerceToDomain
1258 static CoerceToDomain *
1259 _copyCoerceToDomain(CoerceToDomain *from)
1261 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1263 COPY_NODE_FIELD(arg);
1264 COPY_SCALAR_FIELD(resulttype);
1265 COPY_SCALAR_FIELD(resulttypmod);
1266 COPY_SCALAR_FIELD(coercionformat);
1272 * _copyCoerceToDomainValue
1274 static CoerceToDomainValue *
1275 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1277 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1279 COPY_SCALAR_FIELD(typeId);
1280 COPY_SCALAR_FIELD(typeMod);
1288 static SetToDefault *
1289 _copySetToDefault(SetToDefault *from)
1291 SetToDefault *newnode = makeNode(SetToDefault);
1293 COPY_SCALAR_FIELD(typeId);
1294 COPY_SCALAR_FIELD(typeMod);
1300 * _copyCurrentOfExpr
1302 static CurrentOfExpr *
1303 _copyCurrentOfExpr(CurrentOfExpr *from)
1305 CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1307 COPY_SCALAR_FIELD(cvarno);
1308 COPY_STRING_FIELD(cursor_name);
1309 COPY_SCALAR_FIELD(cursor_param);
1317 static TargetEntry *
1318 _copyTargetEntry(TargetEntry *from)
1320 TargetEntry *newnode = makeNode(TargetEntry);
1322 COPY_NODE_FIELD(expr);
1323 COPY_SCALAR_FIELD(resno);
1324 COPY_STRING_FIELD(resname);
1325 COPY_SCALAR_FIELD(ressortgroupref);
1326 COPY_SCALAR_FIELD(resorigtbl);
1327 COPY_SCALAR_FIELD(resorigcol);
1328 COPY_SCALAR_FIELD(resjunk);
1336 static RangeTblRef *
1337 _copyRangeTblRef(RangeTblRef *from)
1339 RangeTblRef *newnode = makeNode(RangeTblRef);
1341 COPY_SCALAR_FIELD(rtindex);
1350 _copyJoinExpr(JoinExpr *from)
1352 JoinExpr *newnode = makeNode(JoinExpr);
1354 COPY_SCALAR_FIELD(jointype);
1355 COPY_SCALAR_FIELD(isNatural);
1356 COPY_NODE_FIELD(larg);
1357 COPY_NODE_FIELD(rarg);
1358 COPY_NODE_FIELD(using);
1359 COPY_NODE_FIELD(quals);
1360 COPY_NODE_FIELD(alias);
1361 COPY_SCALAR_FIELD(rtindex);
1370 _copyFromExpr(FromExpr *from)
1372 FromExpr *newnode = makeNode(FromExpr);
1374 COPY_NODE_FIELD(fromlist);
1375 COPY_NODE_FIELD(quals);
1380 /* ****************************************************************
1381 * relation.h copy functions
1383 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1384 * There are some subsidiary structs that are useful to copy, though.
1385 * ****************************************************************
1392 _copyPathKey(PathKey *from)
1394 PathKey *newnode = makeNode(PathKey);
1396 /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1397 COPY_SCALAR_FIELD(pk_eclass);
1398 COPY_SCALAR_FIELD(pk_opfamily);
1399 COPY_SCALAR_FIELD(pk_strategy);
1400 COPY_SCALAR_FIELD(pk_nulls_first);
1408 static RestrictInfo *
1409 _copyRestrictInfo(RestrictInfo *from)
1411 RestrictInfo *newnode = makeNode(RestrictInfo);
1413 COPY_NODE_FIELD(clause);
1414 COPY_SCALAR_FIELD(is_pushed_down);
1415 COPY_SCALAR_FIELD(outerjoin_delayed);
1416 COPY_SCALAR_FIELD(can_join);
1417 COPY_SCALAR_FIELD(pseudoconstant);
1418 COPY_BITMAPSET_FIELD(clause_relids);
1419 COPY_BITMAPSET_FIELD(required_relids);
1420 COPY_BITMAPSET_FIELD(left_relids);
1421 COPY_BITMAPSET_FIELD(right_relids);
1422 COPY_NODE_FIELD(orclause);
1423 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1424 COPY_SCALAR_FIELD(parent_ec);
1425 COPY_SCALAR_FIELD(eval_cost);
1426 COPY_SCALAR_FIELD(this_selec);
1427 COPY_NODE_FIELD(mergeopfamilies);
1428 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1429 COPY_SCALAR_FIELD(left_ec);
1430 COPY_SCALAR_FIELD(right_ec);
1431 COPY_SCALAR_FIELD(left_em);
1432 COPY_SCALAR_FIELD(right_em);
1433 /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1434 newnode->scansel_cache = NIL;
1435 COPY_SCALAR_FIELD(outer_is_left);
1436 COPY_SCALAR_FIELD(hashjoinoperator);
1437 COPY_SCALAR_FIELD(left_bucketsize);
1438 COPY_SCALAR_FIELD(right_bucketsize);
1444 * _copyOuterJoinInfo
1446 static OuterJoinInfo *
1447 _copyOuterJoinInfo(OuterJoinInfo *from)
1449 OuterJoinInfo *newnode = makeNode(OuterJoinInfo);
1451 COPY_BITMAPSET_FIELD(min_lefthand);
1452 COPY_BITMAPSET_FIELD(min_righthand);
1453 COPY_BITMAPSET_FIELD(syn_lefthand);
1454 COPY_BITMAPSET_FIELD(syn_righthand);
1455 COPY_SCALAR_FIELD(is_full_join);
1456 COPY_SCALAR_FIELD(lhs_strict);
1457 COPY_SCALAR_FIELD(delay_upper_joins);
1465 static InClauseInfo *
1466 _copyInClauseInfo(InClauseInfo *from)
1468 InClauseInfo *newnode = makeNode(InClauseInfo);
1470 COPY_BITMAPSET_FIELD(lefthand);
1471 COPY_BITMAPSET_FIELD(righthand);
1472 COPY_NODE_FIELD(sub_targetlist);
1473 COPY_NODE_FIELD(in_operators);
1479 * _copyAppendRelInfo
1481 static AppendRelInfo *
1482 _copyAppendRelInfo(AppendRelInfo *from)
1484 AppendRelInfo *newnode = makeNode(AppendRelInfo);
1486 COPY_SCALAR_FIELD(parent_relid);
1487 COPY_SCALAR_FIELD(child_relid);
1488 COPY_SCALAR_FIELD(parent_reltype);
1489 COPY_SCALAR_FIELD(child_reltype);
1490 COPY_NODE_FIELD(col_mappings);
1491 COPY_NODE_FIELD(translated_vars);
1492 COPY_SCALAR_FIELD(parent_reloid);
1497 /* ****************************************************************
1498 * parsenodes.h copy functions
1499 * ****************************************************************
1502 static RangeTblEntry *
1503 _copyRangeTblEntry(RangeTblEntry *from)
1505 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1507 COPY_SCALAR_FIELD(rtekind);
1508 COPY_SCALAR_FIELD(relid);
1509 COPY_NODE_FIELD(subquery);
1510 COPY_NODE_FIELD(funcexpr);
1511 COPY_NODE_FIELD(funccoltypes);
1512 COPY_NODE_FIELD(funccoltypmods);
1513 COPY_NODE_FIELD(values_lists);
1514 COPY_SCALAR_FIELD(jointype);
1515 COPY_NODE_FIELD(joinaliasvars);
1516 COPY_NODE_FIELD(alias);
1517 COPY_NODE_FIELD(eref);
1518 COPY_SCALAR_FIELD(inh);
1519 COPY_SCALAR_FIELD(inFromCl);
1520 COPY_SCALAR_FIELD(requiredPerms);
1521 COPY_SCALAR_FIELD(checkAsUser);
1526 static FkConstraint *
1527 _copyFkConstraint(FkConstraint *from)
1529 FkConstraint *newnode = makeNode(FkConstraint);
1531 COPY_STRING_FIELD(constr_name);
1532 COPY_NODE_FIELD(pktable);
1533 COPY_NODE_FIELD(fk_attrs);
1534 COPY_NODE_FIELD(pk_attrs);
1535 COPY_SCALAR_FIELD(fk_matchtype);
1536 COPY_SCALAR_FIELD(fk_upd_action);
1537 COPY_SCALAR_FIELD(fk_del_action);
1538 COPY_SCALAR_FIELD(deferrable);
1539 COPY_SCALAR_FIELD(initdeferred);
1540 COPY_SCALAR_FIELD(skip_validation);
1546 _copySortClause(SortClause *from)
1548 SortClause *newnode = makeNode(SortClause);
1550 COPY_SCALAR_FIELD(tleSortGroupRef);
1551 COPY_SCALAR_FIELD(sortop);
1552 COPY_SCALAR_FIELD(nulls_first);
1557 static GroupClause *
1558 _copyGroupClause(GroupClause *from)
1560 GroupClause *newnode = makeNode(GroupClause);
1562 COPY_SCALAR_FIELD(tleSortGroupRef);
1563 COPY_SCALAR_FIELD(sortop);
1564 COPY_SCALAR_FIELD(nulls_first);
1569 static RowMarkClause *
1570 _copyRowMarkClause(RowMarkClause *from)
1572 RowMarkClause *newnode = makeNode(RowMarkClause);
1574 COPY_SCALAR_FIELD(rti);
1575 COPY_SCALAR_FIELD(forUpdate);
1576 COPY_SCALAR_FIELD(noWait);
1582 _copyAExpr(A_Expr *from)
1584 A_Expr *newnode = makeNode(A_Expr);
1586 COPY_SCALAR_FIELD(kind);
1587 COPY_NODE_FIELD(name);
1588 COPY_NODE_FIELD(lexpr);
1589 COPY_NODE_FIELD(rexpr);
1590 COPY_SCALAR_FIELD(location);
1596 _copyColumnRef(ColumnRef *from)
1598 ColumnRef *newnode = makeNode(ColumnRef);
1600 COPY_NODE_FIELD(fields);
1601 COPY_SCALAR_FIELD(location);
1607 _copyParamRef(ParamRef *from)
1609 ParamRef *newnode = makeNode(ParamRef);
1611 COPY_SCALAR_FIELD(number);
1617 _copyAConst(A_Const *from)
1619 A_Const *newnode = makeNode(A_Const);
1621 /* This part must duplicate _copyValue */
1622 COPY_SCALAR_FIELD(val.type);
1623 switch (from->val.type)
1626 COPY_SCALAR_FIELD(val.val.ival);
1631 COPY_STRING_FIELD(val.val.str);
1637 elog(ERROR, "unrecognized node type: %d",
1638 (int) from->val.type);
1646 _copyFuncCall(FuncCall *from)
1648 FuncCall *newnode = makeNode(FuncCall);
1650 COPY_NODE_FIELD(funcname);
1651 COPY_NODE_FIELD(args);
1652 COPY_SCALAR_FIELD(agg_star);
1653 COPY_SCALAR_FIELD(agg_distinct);
1654 COPY_SCALAR_FIELD(func_variadic);
1655 COPY_SCALAR_FIELD(location);
1661 _copyAIndices(A_Indices *from)
1663 A_Indices *newnode = makeNode(A_Indices);
1665 COPY_NODE_FIELD(lidx);
1666 COPY_NODE_FIELD(uidx);
1671 static A_Indirection *
1672 _copyA_Indirection(A_Indirection *from)
1674 A_Indirection *newnode = makeNode(A_Indirection);
1676 COPY_NODE_FIELD(arg);
1677 COPY_NODE_FIELD(indirection);
1682 static A_ArrayExpr *
1683 _copyA_ArrayExpr(A_ArrayExpr *from)
1685 A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
1687 COPY_NODE_FIELD(elements);
1693 _copyResTarget(ResTarget *from)
1695 ResTarget *newnode = makeNode(ResTarget);
1697 COPY_STRING_FIELD(name);
1698 COPY_NODE_FIELD(indirection);
1699 COPY_NODE_FIELD(val);
1700 COPY_SCALAR_FIELD(location);
1706 _copyTypeName(TypeName *from)
1708 TypeName *newnode = makeNode(TypeName);
1710 COPY_NODE_FIELD(names);
1711 COPY_SCALAR_FIELD(typeid);
1712 COPY_SCALAR_FIELD(setof);
1713 COPY_SCALAR_FIELD(pct_type);
1714 COPY_NODE_FIELD(typmods);
1715 COPY_SCALAR_FIELD(typemod);
1716 COPY_NODE_FIELD(arrayBounds);
1717 COPY_SCALAR_FIELD(location);
1723 _copySortBy(SortBy *from)
1725 SortBy *newnode = makeNode(SortBy);
1727 COPY_SCALAR_FIELD(sortby_dir);
1728 COPY_SCALAR_FIELD(sortby_nulls);
1729 COPY_NODE_FIELD(useOp);
1730 COPY_NODE_FIELD(node);
1735 static RangeSubselect *
1736 _copyRangeSubselect(RangeSubselect *from)
1738 RangeSubselect *newnode = makeNode(RangeSubselect);
1740 COPY_NODE_FIELD(subquery);
1741 COPY_NODE_FIELD(alias);
1746 static RangeFunction *
1747 _copyRangeFunction(RangeFunction *from)
1749 RangeFunction *newnode = makeNode(RangeFunction);
1751 COPY_NODE_FIELD(funccallnode);
1752 COPY_NODE_FIELD(alias);
1753 COPY_NODE_FIELD(coldeflist);
1759 _copyTypeCast(TypeCast *from)
1761 TypeCast *newnode = makeNode(TypeCast);
1763 COPY_NODE_FIELD(arg);
1764 COPY_NODE_FIELD(typename);
1770 _copyIndexElem(IndexElem *from)
1772 IndexElem *newnode = makeNode(IndexElem);
1774 COPY_STRING_FIELD(name);
1775 COPY_NODE_FIELD(expr);
1776 COPY_NODE_FIELD(opclass);
1777 COPY_SCALAR_FIELD(ordering);
1778 COPY_SCALAR_FIELD(nulls_ordering);
1784 _copyColumnDef(ColumnDef *from)
1786 ColumnDef *newnode = makeNode(ColumnDef);
1788 COPY_STRING_FIELD(colname);
1789 COPY_NODE_FIELD(typename);
1790 COPY_SCALAR_FIELD(inhcount);
1791 COPY_SCALAR_FIELD(is_local);
1792 COPY_SCALAR_FIELD(is_not_null);
1793 COPY_NODE_FIELD(raw_default);
1794 COPY_STRING_FIELD(cooked_default);
1795 COPY_NODE_FIELD(constraints);
1801 _copyConstraint(Constraint *from)
1803 Constraint *newnode = makeNode(Constraint);
1805 COPY_SCALAR_FIELD(contype);
1806 COPY_STRING_FIELD(name);
1807 COPY_NODE_FIELD(raw_expr);
1808 COPY_STRING_FIELD(cooked_expr);
1809 COPY_NODE_FIELD(keys);
1810 COPY_NODE_FIELD(options);
1811 COPY_STRING_FIELD(indexspace);
1817 _copyDefElem(DefElem *from)
1819 DefElem *newnode = makeNode(DefElem);
1821 COPY_STRING_FIELD(defname);
1822 COPY_NODE_FIELD(arg);
1827 static LockingClause *
1828 _copyLockingClause(LockingClause *from)
1830 LockingClause *newnode = makeNode(LockingClause);
1832 COPY_NODE_FIELD(lockedRels);
1833 COPY_SCALAR_FIELD(forUpdate);
1834 COPY_SCALAR_FIELD(noWait);
1839 static XmlSerialize *
1840 _copyXmlSerialize(XmlSerialize *from)
1842 XmlSerialize *newnode = makeNode(XmlSerialize);
1844 COPY_SCALAR_FIELD(xmloption);
1845 COPY_NODE_FIELD(expr);
1846 COPY_NODE_FIELD(typename);
1852 _copyQuery(Query *from)
1854 Query *newnode = makeNode(Query);
1856 COPY_SCALAR_FIELD(commandType);
1857 COPY_SCALAR_FIELD(querySource);
1858 COPY_SCALAR_FIELD(canSetTag);
1859 COPY_NODE_FIELD(utilityStmt);
1860 COPY_SCALAR_FIELD(resultRelation);
1861 COPY_NODE_FIELD(intoClause);
1862 COPY_SCALAR_FIELD(hasAggs);
1863 COPY_SCALAR_FIELD(hasSubLinks);
1864 COPY_NODE_FIELD(rtable);
1865 COPY_NODE_FIELD(jointree);
1866 COPY_NODE_FIELD(targetList);
1867 COPY_NODE_FIELD(returningList);
1868 COPY_NODE_FIELD(groupClause);
1869 COPY_NODE_FIELD(havingQual);
1870 COPY_NODE_FIELD(distinctClause);
1871 COPY_NODE_FIELD(sortClause);
1872 COPY_NODE_FIELD(limitOffset);
1873 COPY_NODE_FIELD(limitCount);
1874 COPY_NODE_FIELD(rowMarks);
1875 COPY_NODE_FIELD(setOperations);
1881 _copyInsertStmt(InsertStmt *from)
1883 InsertStmt *newnode = makeNode(InsertStmt);
1885 COPY_NODE_FIELD(relation);
1886 COPY_NODE_FIELD(cols);
1887 COPY_NODE_FIELD(selectStmt);
1888 COPY_NODE_FIELD(returningList);
1894 _copyDeleteStmt(DeleteStmt *from)
1896 DeleteStmt *newnode = makeNode(DeleteStmt);
1898 COPY_NODE_FIELD(relation);
1899 COPY_NODE_FIELD(usingClause);
1900 COPY_NODE_FIELD(whereClause);
1901 COPY_NODE_FIELD(returningList);
1907 _copyUpdateStmt(UpdateStmt *from)
1909 UpdateStmt *newnode = makeNode(UpdateStmt);
1911 COPY_NODE_FIELD(relation);
1912 COPY_NODE_FIELD(targetList);
1913 COPY_NODE_FIELD(whereClause);
1914 COPY_NODE_FIELD(fromClause);
1915 COPY_NODE_FIELD(returningList);
1921 _copySelectStmt(SelectStmt *from)
1923 SelectStmt *newnode = makeNode(SelectStmt);
1925 COPY_NODE_FIELD(distinctClause);
1926 COPY_NODE_FIELD(intoClause);
1927 COPY_NODE_FIELD(targetList);
1928 COPY_NODE_FIELD(fromClause);
1929 COPY_NODE_FIELD(whereClause);
1930 COPY_NODE_FIELD(groupClause);
1931 COPY_NODE_FIELD(havingClause);
1932 COPY_NODE_FIELD(valuesLists);
1933 COPY_NODE_FIELD(sortClause);
1934 COPY_NODE_FIELD(limitOffset);
1935 COPY_NODE_FIELD(limitCount);
1936 COPY_NODE_FIELD(lockingClause);
1937 COPY_SCALAR_FIELD(op);
1938 COPY_SCALAR_FIELD(all);
1939 COPY_NODE_FIELD(larg);
1940 COPY_NODE_FIELD(rarg);
1945 static SetOperationStmt *
1946 _copySetOperationStmt(SetOperationStmt *from)
1948 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1950 COPY_SCALAR_FIELD(op);
1951 COPY_SCALAR_FIELD(all);
1952 COPY_NODE_FIELD(larg);
1953 COPY_NODE_FIELD(rarg);
1954 COPY_NODE_FIELD(colTypes);
1955 COPY_NODE_FIELD(colTypmods);
1960 static AlterTableStmt *
1961 _copyAlterTableStmt(AlterTableStmt *from)
1963 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1965 COPY_NODE_FIELD(relation);
1966 COPY_NODE_FIELD(cmds);
1967 COPY_SCALAR_FIELD(relkind);
1972 static AlterTableCmd *
1973 _copyAlterTableCmd(AlterTableCmd *from)
1975 AlterTableCmd *newnode = makeNode(AlterTableCmd);
1977 COPY_SCALAR_FIELD(subtype);
1978 COPY_STRING_FIELD(name);
1979 COPY_NODE_FIELD(def);
1980 COPY_NODE_FIELD(transform);
1981 COPY_SCALAR_FIELD(behavior);
1986 static AlterDomainStmt *
1987 _copyAlterDomainStmt(AlterDomainStmt *from)
1989 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1991 COPY_SCALAR_FIELD(subtype);
1992 COPY_NODE_FIELD(typename);
1993 COPY_STRING_FIELD(name);
1994 COPY_NODE_FIELD(def);
1995 COPY_SCALAR_FIELD(behavior);
2001 _copyGrantStmt(GrantStmt *from)
2003 GrantStmt *newnode = makeNode(GrantStmt);
2005 COPY_SCALAR_FIELD(is_grant);
2006 COPY_SCALAR_FIELD(objtype);
2007 COPY_NODE_FIELD(objects);
2008 COPY_NODE_FIELD(privileges);
2009 COPY_NODE_FIELD(grantees);
2010 COPY_SCALAR_FIELD(grant_option);
2011 COPY_SCALAR_FIELD(behavior);
2016 static PrivGrantee *
2017 _copyPrivGrantee(PrivGrantee *from)
2019 PrivGrantee *newnode = makeNode(PrivGrantee);
2021 COPY_STRING_FIELD(rolname);
2026 static FuncWithArgs *
2027 _copyFuncWithArgs(FuncWithArgs *from)
2029 FuncWithArgs *newnode = makeNode(FuncWithArgs);
2031 COPY_NODE_FIELD(funcname);
2032 COPY_NODE_FIELD(funcargs);
2037 static GrantRoleStmt *
2038 _copyGrantRoleStmt(GrantRoleStmt *from)
2040 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2042 COPY_NODE_FIELD(granted_roles);
2043 COPY_NODE_FIELD(grantee_roles);
2044 COPY_SCALAR_FIELD(is_grant);
2045 COPY_SCALAR_FIELD(admin_opt);
2046 COPY_STRING_FIELD(grantor);
2047 COPY_SCALAR_FIELD(behavior);
2052 static DeclareCursorStmt *
2053 _copyDeclareCursorStmt(DeclareCursorStmt *from)
2055 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2057 COPY_STRING_FIELD(portalname);
2058 COPY_SCALAR_FIELD(options);
2059 COPY_NODE_FIELD(query);
2064 static ClosePortalStmt *
2065 _copyClosePortalStmt(ClosePortalStmt *from)
2067 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2069 COPY_STRING_FIELD(portalname);
2074 static ClusterStmt *
2075 _copyClusterStmt(ClusterStmt *from)
2077 ClusterStmt *newnode = makeNode(ClusterStmt);
2079 COPY_NODE_FIELD(relation);
2080 COPY_STRING_FIELD(indexname);
2086 _copyCopyStmt(CopyStmt *from)
2088 CopyStmt *newnode = makeNode(CopyStmt);
2090 COPY_NODE_FIELD(relation);
2091 COPY_NODE_FIELD(query);
2092 COPY_NODE_FIELD(attlist);
2093 COPY_SCALAR_FIELD(is_from);
2094 COPY_STRING_FIELD(filename);
2095 COPY_NODE_FIELD(options);
2101 _copyCreateStmt(CreateStmt *from)
2103 CreateStmt *newnode = makeNode(CreateStmt);
2105 COPY_NODE_FIELD(relation);
2106 COPY_NODE_FIELD(tableElts);
2107 COPY_NODE_FIELD(inhRelations);
2108 COPY_NODE_FIELD(constraints);
2109 COPY_NODE_FIELD(options);
2110 COPY_SCALAR_FIELD(oncommit);
2111 COPY_STRING_FIELD(tablespacename);
2116 static InhRelation *
2117 _copyInhRelation(InhRelation *from)
2119 InhRelation *newnode = makeNode(InhRelation);
2121 COPY_NODE_FIELD(relation);
2122 COPY_NODE_FIELD(options);
2128 _copyDefineStmt(DefineStmt *from)
2130 DefineStmt *newnode = makeNode(DefineStmt);
2132 COPY_SCALAR_FIELD(kind);
2133 COPY_SCALAR_FIELD(oldstyle);
2134 COPY_NODE_FIELD(defnames);
2135 COPY_NODE_FIELD(args);
2136 COPY_NODE_FIELD(definition);
2142 _copyDropStmt(DropStmt *from)
2144 DropStmt *newnode = makeNode(DropStmt);
2146 COPY_NODE_FIELD(objects);
2147 COPY_SCALAR_FIELD(removeType);
2148 COPY_SCALAR_FIELD(behavior);
2149 COPY_SCALAR_FIELD(missing_ok);
2154 static TruncateStmt *
2155 _copyTruncateStmt(TruncateStmt *from)
2157 TruncateStmt *newnode = makeNode(TruncateStmt);
2159 COPY_NODE_FIELD(relations);
2160 COPY_SCALAR_FIELD(restart_seqs);
2161 COPY_SCALAR_FIELD(behavior);
2166 static CommentStmt *
2167 _copyCommentStmt(CommentStmt *from)
2169 CommentStmt *newnode = makeNode(CommentStmt);
2171 COPY_SCALAR_FIELD(objtype);
2172 COPY_NODE_FIELD(objname);
2173 COPY_NODE_FIELD(objargs);
2174 COPY_STRING_FIELD(comment);
2180 _copyFetchStmt(FetchStmt *from)
2182 FetchStmt *newnode = makeNode(FetchStmt);
2184 COPY_SCALAR_FIELD(direction);
2185 COPY_SCALAR_FIELD(howMany);
2186 COPY_STRING_FIELD(portalname);
2187 COPY_SCALAR_FIELD(ismove);
2193 _copyIndexStmt(IndexStmt *from)
2195 IndexStmt *newnode = makeNode(IndexStmt);
2197 COPY_STRING_FIELD(idxname);
2198 COPY_NODE_FIELD(relation);
2199 COPY_STRING_FIELD(accessMethod);
2200 COPY_STRING_FIELD(tableSpace);
2201 COPY_NODE_FIELD(indexParams);
2202 COPY_NODE_FIELD(options);
2203 COPY_NODE_FIELD(whereClause);
2204 COPY_SCALAR_FIELD(unique);
2205 COPY_SCALAR_FIELD(primary);
2206 COPY_SCALAR_FIELD(isconstraint);
2207 COPY_SCALAR_FIELD(concurrent);
2212 static CreateFunctionStmt *
2213 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2215 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2217 COPY_SCALAR_FIELD(replace);
2218 COPY_NODE_FIELD(funcname);
2219 COPY_NODE_FIELD(parameters);
2220 COPY_NODE_FIELD(returnType);
2221 COPY_NODE_FIELD(options);
2222 COPY_NODE_FIELD(withClause);
2227 static FunctionParameter *
2228 _copyFunctionParameter(FunctionParameter *from)
2230 FunctionParameter *newnode = makeNode(FunctionParameter);
2232 COPY_STRING_FIELD(name);
2233 COPY_NODE_FIELD(argType);
2234 COPY_SCALAR_FIELD(mode);
2239 static AlterFunctionStmt *
2240 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2242 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2244 COPY_NODE_FIELD(func);
2245 COPY_NODE_FIELD(actions);
2250 static RemoveFuncStmt *
2251 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2253 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2255 COPY_SCALAR_FIELD(kind);
2256 COPY_NODE_FIELD(name);
2257 COPY_NODE_FIELD(args);
2258 COPY_SCALAR_FIELD(behavior);
2259 COPY_SCALAR_FIELD(missing_ok);
2264 static RemoveOpClassStmt *
2265 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2267 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2269 COPY_NODE_FIELD(opclassname);
2270 COPY_STRING_FIELD(amname);
2271 COPY_SCALAR_FIELD(behavior);
2272 COPY_SCALAR_FIELD(missing_ok);
2277 static RemoveOpFamilyStmt *
2278 _copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
2280 RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);
2282 COPY_NODE_FIELD(opfamilyname);
2283 COPY_STRING_FIELD(amname);
2284 COPY_SCALAR_FIELD(behavior);
2285 COPY_SCALAR_FIELD(missing_ok);
2291 _copyRenameStmt(RenameStmt *from)
2293 RenameStmt *newnode = makeNode(RenameStmt);
2295 COPY_SCALAR_FIELD(renameType);
2296 COPY_NODE_FIELD(relation);
2297 COPY_NODE_FIELD(object);
2298 COPY_NODE_FIELD(objarg);
2299 COPY_STRING_FIELD(subname);
2300 COPY_STRING_FIELD(newname);
2305 static AlterObjectSchemaStmt *
2306 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2308 AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2310 COPY_SCALAR_FIELD(objectType);
2311 COPY_NODE_FIELD(relation);
2312 COPY_NODE_FIELD(object);
2313 COPY_NODE_FIELD(objarg);
2314 COPY_STRING_FIELD(addname);
2315 COPY_STRING_FIELD(newschema);
2320 static AlterOwnerStmt *
2321 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2323 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2325 COPY_SCALAR_FIELD(objectType);
2326 COPY_NODE_FIELD(relation);
2327 COPY_NODE_FIELD(object);
2328 COPY_NODE_FIELD(objarg);
2329 COPY_STRING_FIELD(addname);
2330 COPY_STRING_FIELD(newowner);
2336 _copyRuleStmt(RuleStmt *from)
2338 RuleStmt *newnode = makeNode(RuleStmt);
2340 COPY_NODE_FIELD(relation);
2341 COPY_STRING_FIELD(rulename);
2342 COPY_NODE_FIELD(whereClause);
2343 COPY_SCALAR_FIELD(event);
2344 COPY_SCALAR_FIELD(instead);
2345 COPY_NODE_FIELD(actions);
2346 COPY_SCALAR_FIELD(replace);
2352 _copyNotifyStmt(NotifyStmt *from)
2354 NotifyStmt *newnode = makeNode(NotifyStmt);
2356 COPY_NODE_FIELD(relation);
2362 _copyListenStmt(ListenStmt *from)
2364 ListenStmt *newnode = makeNode(ListenStmt);
2366 COPY_NODE_FIELD(relation);
2371 static UnlistenStmt *
2372 _copyUnlistenStmt(UnlistenStmt *from)
2374 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2376 COPY_NODE_FIELD(relation);
2381 static TransactionStmt *
2382 _copyTransactionStmt(TransactionStmt *from)
2384 TransactionStmt *newnode = makeNode(TransactionStmt);
2386 COPY_SCALAR_FIELD(kind);
2387 COPY_NODE_FIELD(options);
2388 COPY_STRING_FIELD(gid);
2393 static CompositeTypeStmt *
2394 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2396 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2398 COPY_NODE_FIELD(typevar);
2399 COPY_NODE_FIELD(coldeflist);
2404 static CreateEnumStmt *
2405 _copyCreateEnumStmt(CreateEnumStmt *from)
2407 CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
2409 COPY_NODE_FIELD(typename);
2410 COPY_NODE_FIELD(vals);
2416 _copyViewStmt(ViewStmt *from)
2418 ViewStmt *newnode = makeNode(ViewStmt);
2420 COPY_NODE_FIELD(view);
2421 COPY_NODE_FIELD(aliases);
2422 COPY_NODE_FIELD(query);
2423 COPY_SCALAR_FIELD(replace);
2429 _copyLoadStmt(LoadStmt *from)
2431 LoadStmt *newnode = makeNode(LoadStmt);
2433 COPY_STRING_FIELD(filename);
2438 static CreateDomainStmt *
2439 _copyCreateDomainStmt(CreateDomainStmt *from)
2441 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2443 COPY_NODE_FIELD(domainname);
2444 COPY_NODE_FIELD(typename);
2445 COPY_NODE_FIELD(constraints);
2450 static CreateOpClassStmt *
2451 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2453 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2455 COPY_NODE_FIELD(opclassname);
2456 COPY_NODE_FIELD(opfamilyname);
2457 COPY_STRING_FIELD(amname);
2458 COPY_NODE_FIELD(datatype);
2459 COPY_NODE_FIELD(items);
2460 COPY_SCALAR_FIELD(isDefault);
2465 static CreateOpClassItem *
2466 _copyCreateOpClassItem(CreateOpClassItem *from)
2468 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2470 COPY_SCALAR_FIELD(itemtype);
2471 COPY_NODE_FIELD(name);
2472 COPY_NODE_FIELD(args);
2473 COPY_SCALAR_FIELD(number);
2474 COPY_NODE_FIELD(class_args);
2475 COPY_NODE_FIELD(storedtype);
2480 static CreateOpFamilyStmt *
2481 _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
2483 CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
2485 COPY_NODE_FIELD(opfamilyname);
2486 COPY_STRING_FIELD(amname);
2491 static AlterOpFamilyStmt *
2492 _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
2494 AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
2496 COPY_NODE_FIELD(opfamilyname);
2497 COPY_STRING_FIELD(amname);
2498 COPY_SCALAR_FIELD(isDrop);
2499 COPY_NODE_FIELD(items);
2504 static CreatedbStmt *
2505 _copyCreatedbStmt(CreatedbStmt *from)
2507 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2509 COPY_STRING_FIELD(dbname);
2510 COPY_NODE_FIELD(options);
2515 static AlterDatabaseStmt *
2516 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2518 AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2520 COPY_STRING_FIELD(dbname);
2521 COPY_NODE_FIELD(options);
2526 static AlterDatabaseSetStmt *
2527 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2529 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2531 COPY_STRING_FIELD(dbname);
2532 COPY_NODE_FIELD(setstmt);
2538 _copyDropdbStmt(DropdbStmt *from)
2540 DropdbStmt *newnode = makeNode(DropdbStmt);
2542 COPY_STRING_FIELD(dbname);
2543 COPY_SCALAR_FIELD(missing_ok);
2549 _copyVacuumStmt(VacuumStmt *from)
2551 VacuumStmt *newnode = makeNode(VacuumStmt);
2553 COPY_SCALAR_FIELD(vacuum);
2554 COPY_SCALAR_FIELD(full);
2555 COPY_SCALAR_FIELD(analyze);
2556 COPY_SCALAR_FIELD(verbose);
2557 COPY_SCALAR_FIELD(freeze_min_age);
2558 COPY_NODE_FIELD(relation);
2559 COPY_NODE_FIELD(va_cols);
2564 static ExplainStmt *
2565 _copyExplainStmt(ExplainStmt *from)
2567 ExplainStmt *newnode = makeNode(ExplainStmt);
2569 COPY_NODE_FIELD(query);
2570 COPY_SCALAR_FIELD(verbose);
2571 COPY_SCALAR_FIELD(analyze);
2576 static CreateSeqStmt *
2577 _copyCreateSeqStmt(CreateSeqStmt *from)
2579 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2581 COPY_NODE_FIELD(sequence);
2582 COPY_NODE_FIELD(options);
2587 static AlterSeqStmt *
2588 _copyAlterSeqStmt(AlterSeqStmt *from)
2590 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2592 COPY_NODE_FIELD(sequence);
2593 COPY_NODE_FIELD(options);
2598 static VariableSetStmt *
2599 _copyVariableSetStmt(VariableSetStmt *from)
2601 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2603 COPY_SCALAR_FIELD(kind);
2604 COPY_STRING_FIELD(name);
2605 COPY_NODE_FIELD(args);
2606 COPY_SCALAR_FIELD(is_local);
2611 static VariableShowStmt *
2612 _copyVariableShowStmt(VariableShowStmt *from)
2614 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2616 COPY_STRING_FIELD(name);
2621 static DiscardStmt *
2622 _copyDiscardStmt(DiscardStmt *from)
2624 DiscardStmt *newnode = makeNode(DiscardStmt);
2626 COPY_SCALAR_FIELD(target);
2631 static CreateTableSpaceStmt *
2632 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2634 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2636 COPY_STRING_FIELD(tablespacename);
2637 COPY_STRING_FIELD(owner);
2638 COPY_STRING_FIELD(location);
2643 static DropTableSpaceStmt *
2644 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2646 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2648 COPY_STRING_FIELD(tablespacename);
2649 COPY_SCALAR_FIELD(missing_ok);
2654 static CreateTrigStmt *
2655 _copyCreateTrigStmt(CreateTrigStmt *from)
2657 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2659 COPY_STRING_FIELD(trigname);
2660 COPY_NODE_FIELD(relation);
2661 COPY_NODE_FIELD(funcname);
2662 COPY_NODE_FIELD(args);
2663 COPY_SCALAR_FIELD(before);
2664 COPY_SCALAR_FIELD(row);
2665 strcpy(newnode->actions, from->actions); /* in-line string field */
2666 COPY_SCALAR_FIELD(isconstraint);
2667 COPY_SCALAR_FIELD(deferrable);
2668 COPY_SCALAR_FIELD(initdeferred);
2669 COPY_NODE_FIELD(constrrel);
2674 static DropPropertyStmt *
2675 _copyDropPropertyStmt(DropPropertyStmt *from)
2677 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2679 COPY_NODE_FIELD(relation);
2680 COPY_STRING_FIELD(property);
2681 COPY_SCALAR_FIELD(removeType);
2682 COPY_SCALAR_FIELD(behavior);
2683 COPY_SCALAR_FIELD(missing_ok);
2688 static CreatePLangStmt *
2689 _copyCreatePLangStmt(CreatePLangStmt *from)
2691 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2693 COPY_STRING_FIELD(plname);
2694 COPY_NODE_FIELD(plhandler);
2695 COPY_NODE_FIELD(plvalidator);
2696 COPY_SCALAR_FIELD(pltrusted);
2701 static DropPLangStmt *
2702 _copyDropPLangStmt(DropPLangStmt *from)
2704 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2706 COPY_STRING_FIELD(plname);
2707 COPY_SCALAR_FIELD(behavior);
2708 COPY_SCALAR_FIELD(missing_ok);
2713 static CreateRoleStmt *
2714 _copyCreateRoleStmt(CreateRoleStmt *from)
2716 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2718 COPY_SCALAR_FIELD(stmt_type);
2719 COPY_STRING_FIELD(role);
2720 COPY_NODE_FIELD(options);
2725 static AlterRoleStmt *
2726 _copyAlterRoleStmt(AlterRoleStmt *from)
2728 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2730 COPY_STRING_FIELD(role);
2731 COPY_NODE_FIELD(options);
2732 COPY_SCALAR_FIELD(action);
2737 static AlterRoleSetStmt *
2738 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2740 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2742 COPY_STRING_FIELD(role);
2743 COPY_NODE_FIELD(setstmt);
2748 static DropRoleStmt *
2749 _copyDropRoleStmt(DropRoleStmt *from)
2751 DropRoleStmt *newnode = makeNode(DropRoleStmt);
2753 COPY_NODE_FIELD(roles);
2754 COPY_SCALAR_FIELD(missing_ok);
2760 _copyLockStmt(LockStmt *from)
2762 LockStmt *newnode = makeNode(LockStmt);
2764 COPY_NODE_FIELD(relations);
2765 COPY_SCALAR_FIELD(mode);
2766 COPY_SCALAR_FIELD(nowait);
2771 static ConstraintsSetStmt *
2772 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2774 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2776 COPY_NODE_FIELD(constraints);
2777 COPY_SCALAR_FIELD(deferred);
2782 static ReindexStmt *
2783 _copyReindexStmt(ReindexStmt *from)
2785 ReindexStmt *newnode = makeNode(ReindexStmt);
2787 COPY_SCALAR_FIELD(kind);
2788 COPY_NODE_FIELD(relation);
2789 COPY_STRING_FIELD(name);
2790 COPY_SCALAR_FIELD(do_system);
2791 COPY_SCALAR_FIELD(do_user);
2796 static CreateSchemaStmt *
2797 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2799 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2801 COPY_STRING_FIELD(schemaname);
2802 COPY_STRING_FIELD(authid);
2803 COPY_NODE_FIELD(schemaElts);
2808 static CreateConversionStmt *
2809 _copyCreateConversionStmt(CreateConversionStmt *from)
2811 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2813 COPY_NODE_FIELD(conversion_name);
2814 COPY_STRING_FIELD(for_encoding_name);
2815 COPY_STRING_FIELD(to_encoding_name);
2816 COPY_NODE_FIELD(func_name);
2817 COPY_SCALAR_FIELD(def);
2822 static CreateCastStmt *
2823 _copyCreateCastStmt(CreateCastStmt *from)
2825 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2827 COPY_NODE_FIELD(sourcetype);
2828 COPY_NODE_FIELD(targettype);
2829 COPY_NODE_FIELD(func);
2830 COPY_SCALAR_FIELD(context);
2835 static DropCastStmt *
2836 _copyDropCastStmt(DropCastStmt *from)
2838 DropCastStmt *newnode = makeNode(DropCastStmt);
2840 COPY_NODE_FIELD(sourcetype);
2841 COPY_NODE_FIELD(targettype);
2842 COPY_SCALAR_FIELD(behavior);
2843 COPY_SCALAR_FIELD(missing_ok);
2848 static PrepareStmt *
2849 _copyPrepareStmt(PrepareStmt *from)
2851 PrepareStmt *newnode = makeNode(PrepareStmt);
2853 COPY_STRING_FIELD(name);
2854 COPY_NODE_FIELD(argtypes);
2855 COPY_NODE_FIELD(query);
2860 static ExecuteStmt *
2861 _copyExecuteStmt(ExecuteStmt *from)
2863 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2865 COPY_STRING_FIELD(name);
2866 COPY_NODE_FIELD(into);
2867 COPY_NODE_FIELD(params);
2872 static DeallocateStmt *
2873 _copyDeallocateStmt(DeallocateStmt *from)
2875 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2877 COPY_STRING_FIELD(name);
2882 static DropOwnedStmt *
2883 _copyDropOwnedStmt(DropOwnedStmt *from)
2885 DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
2887 COPY_NODE_FIELD(roles);
2888 COPY_SCALAR_FIELD(behavior);
2893 static ReassignOwnedStmt *
2894 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
2896 ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
2898 COPY_NODE_FIELD(roles);
2899 COPY_SCALAR_FIELD(newrole);
2904 static AlterTSDictionaryStmt *
2905 _copyAlterTSDictionaryStmt(AlterTSDictionaryStmt *from)
2907 AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
2909 COPY_NODE_FIELD(dictname);
2910 COPY_NODE_FIELD(options);
2915 static AlterTSConfigurationStmt *
2916 _copyAlterTSConfigurationStmt(AlterTSConfigurationStmt *from)
2918 AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
2920 COPY_NODE_FIELD(cfgname);
2921 COPY_NODE_FIELD(tokentype);
2922 COPY_NODE_FIELD(dicts);
2923 COPY_SCALAR_FIELD(override);
2924 COPY_SCALAR_FIELD(replace);
2925 COPY_SCALAR_FIELD(missing_ok);
2930 /* ****************************************************************
2931 * pg_list.h copy functions
2932 * ****************************************************************
2936 * Perform a deep copy of the specified list, using copyObject(). The
2937 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2938 * need deep copies, so they should be copied via list_copy()
2940 #define COPY_NODE_CELL(new, old) \
2941 (new) = (ListCell *) palloc(sizeof(ListCell)); \
2942 lfirst(new) = copyObject(lfirst(old));
2945 _copyList(List *from)
2951 Assert(list_length(from) >= 1);
2953 new = makeNode(List);
2954 new->length = from->length;
2956 COPY_NODE_CELL(new->head, from->head);
2957 prev_new = new->head;
2958 curr_old = lnext(from->head);
2962 COPY_NODE_CELL(prev_new->next, curr_old);
2963 prev_new = prev_new->next;
2964 curr_old = curr_old->next;
2966 prev_new->next = NULL;
2967 new->tail = prev_new;
2972 /* ****************************************************************
2973 * value.h copy functions
2974 * ****************************************************************
2977 _copyValue(Value *from)
2979 Value *newnode = makeNode(Value);
2981 /* See also _copyAConst when changing this code! */
2983 COPY_SCALAR_FIELD(type);
2987 COPY_SCALAR_FIELD(val.ival);
2992 COPY_STRING_FIELD(val.str);
2998 elog(ERROR, "unrecognized node type: %d",
3008 * Create a copy of a Node tree or list. This is a "deep" copy: all
3009 * substructure is copied too, recursively.
3012 copyObject(void *from)
3019 switch (nodeTag(from))
3025 retval = _copyPlannedStmt(from);
3028 retval = _copyPlan(from);
3031 retval = _copyResult(from);
3034 retval = _copyAppend(from);
3037 retval = _copyBitmapAnd(from);
3040 retval = _copyBitmapOr(from);
3043 retval = _copyScan(from);
3046 retval = _copySeqScan(from);
3049 retval = _copyIndexScan(from);
3051 case T_BitmapIndexScan:
3052 retval = _copyBitmapIndexScan(from);
3054 case T_BitmapHeapScan:
3055 retval = _copyBitmapHeapScan(from);
3058 retval = _copyTidScan(from);
3060 case T_SubqueryScan:
3061 retval = _copySubqueryScan(from);
3063 case T_FunctionScan:
3064 retval = _copyFunctionScan(from);
3067 retval = _copyValuesScan(from);
3070 retval = _copyJoin(from);
3073 retval = _copyNestLoop(from);
3076 retval = _copyMergeJoin(from);
3079 retval = _copyHashJoin(from);
3082 retval = _copyMaterial(from);
3085 retval = _copySort(from);
3088 retval = _copyGroup(from);
3091 retval = _copyAgg(from);
3094 retval = _copyUnique(from);
3097 retval = _copyHash(from);
3100 retval = _copySetOp(from);
3103 retval = _copyLimit(from);
3110 retval = _copyAlias(from);
3113 retval = _copyRangeVar(from);
3116 retval = _copyIntoClause(from);
3119 retval = _copyVar(from);
3122 retval = _copyConst(from);
3125 retval = _copyParam(from);
3128 retval = _copyAggref(from);
3131 retval = _copyArrayRef(from);
3134 retval = _copyFuncExpr(from);
3137 retval = _copyOpExpr(from);
3139 case T_DistinctExpr:
3140 retval = _copyDistinctExpr(from);
3142 case T_ScalarArrayOpExpr:
3143 retval = _copyScalarArrayOpExpr(from);
3146 retval = _copyBoolExpr(from);
3149 retval = _copySubLink(from);
3152 retval = _copySubPlan(from);
3155 retval = _copyFieldSelect(from);
3158 retval = _copyFieldStore(from);
3161 retval = _copyRelabelType(from);
3164 retval = _copyCoerceViaIO(from);
3166 case T_ArrayCoerceExpr:
3167 retval = _copyArrayCoerceExpr(from);
3169 case T_ConvertRowtypeExpr:
3170 retval = _copyConvertRowtypeExpr(from);
3173 retval = _copyCaseExpr(from);
3176 retval = _copyCaseWhen(from);
3178 case T_CaseTestExpr:
3179 retval = _copyCaseTestExpr(from);
3182 retval = _copyArrayExpr(from);
3185 retval = _copyRowExpr(from);
3187 case T_RowCompareExpr:
3188 retval = _copyRowCompareExpr(from);
3190 case T_CoalesceExpr:
3191 retval = _copyCoalesceExpr(from);
3194 retval = _copyMinMaxExpr(from);
3197 retval = _copyXmlExpr(from);
3200 retval = _copyNullIfExpr(from);
3203 retval = _copyNullTest(from);
3206 retval = _copyBooleanTest(from);
3208 case T_CoerceToDomain:
3209 retval = _copyCoerceToDomain(from);
3211 case T_CoerceToDomainValue:
3212 retval = _copyCoerceToDomainValue(from);
3214 case T_SetToDefault:
3215 retval = _copySetToDefault(from);
3217 case T_CurrentOfExpr:
3218 retval = _copyCurrentOfExpr(from);
3221 retval = _copyTargetEntry(from);
3224 retval = _copyRangeTblRef(from);
3227 retval = _copyJoinExpr(from);
3230 retval = _copyFromExpr(from);
3237 retval = _copyPathKey(from);
3239 case T_RestrictInfo:
3240 retval = _copyRestrictInfo(from);
3242 case T_OuterJoinInfo:
3243 retval = _copyOuterJoinInfo(from);
3245 case T_InClauseInfo:
3246 retval = _copyInClauseInfo(from);
3248 case T_AppendRelInfo:
3249 retval = _copyAppendRelInfo(from);
3260 retval = _copyValue(from);
3267 retval = _copyList(from);
3271 * Lists of integers and OIDs don't need to be deep-copied, so we
3272 * perform a shallow copy via list_copy()
3276 retval = list_copy(from);
3283 retval = _copyQuery(from);
3286 retval = _copyInsertStmt(from);
3289 retval = _copyDeleteStmt(from);
3292 retval = _copyUpdateStmt(from);
3295 retval = _copySelectStmt(from);
3297 case T_SetOperationStmt:
3298 retval = _copySetOperationStmt(from);
3300 case T_AlterTableStmt:
3301 retval = _copyAlterTableStmt(from);
3303 case T_AlterTableCmd:
3304 retval = _copyAlterTableCmd(from);
3306 case T_AlterDomainStmt:
3307 retval = _copyAlterDomainStmt(from);
3310 retval = _copyGrantStmt(from);
3312 case T_GrantRoleStmt:
3313 retval = _copyGrantRoleStmt(from);
3315 case T_DeclareCursorStmt:
3316 retval = _copyDeclareCursorStmt(from);
3318 case T_ClosePortalStmt:
3319 retval = _copyClosePortalStmt(from);
3322 retval = _copyClusterStmt(from);
3325 retval = _copyCopyStmt(from);
3328 retval = _copyCreateStmt(from);
3331 retval = _copyInhRelation(from);
3334 retval = _copyDefineStmt(from);
3337 retval = _copyDropStmt(from);
3339 case T_TruncateStmt:
3340 retval = _copyTruncateStmt(from);
3343 retval = _copyCommentStmt(from);
3346 retval = _copyFetchStmt(from);
3349 retval = _copyIndexStmt(from);
3351 case T_CreateFunctionStmt:
3352 retval = _copyCreateFunctionStmt(from);
3354 case T_FunctionParameter:
3355 retval = _copyFunctionParameter(from);
3357 case T_AlterFunctionStmt:
3358 retval = _copyAlterFunctionStmt(from);
3360 case T_RemoveFuncStmt:
3361 retval = _copyRemoveFuncStmt(from);
3363 case T_RemoveOpClassStmt:
3364 retval = _copyRemoveOpClassStmt(from);
3366 case T_RemoveOpFamilyStmt:
3367 retval = _copyRemoveOpFamilyStmt(from);
3370 retval = _copyRenameStmt(from);
3372 case T_AlterObjectSchemaStmt:
3373 retval = _copyAlterObjectSchemaStmt(from);
3375 case T_AlterOwnerStmt:
3376 retval = _copyAlterOwnerStmt(from);
3379 retval = _copyRuleStmt(from);
3382 retval = _copyNotifyStmt(from);
3385 retval = _copyListenStmt(from);
3387 case T_UnlistenStmt:
3388 retval = _copyUnlistenStmt(from);
3390 case T_TransactionStmt:
3391 retval = _copyTransactionStmt(from);
3393 case T_CompositeTypeStmt:
3394 retval = _copyCompositeTypeStmt(from);
3396 case T_CreateEnumStmt:
3397 retval = _copyCreateEnumStmt(from);
3400 retval = _copyViewStmt(from);
3403 retval = _copyLoadStmt(from);
3405 case T_CreateDomainStmt:
3406 retval = _copyCreateDomainStmt(from);
3408 case T_CreateOpClassStmt:
3409 retval = _copyCreateOpClassStmt(from);
3411 case T_CreateOpClassItem:
3412 retval = _copyCreateOpClassItem(from);
3414 case T_CreateOpFamilyStmt:
3415 retval = _copyCreateOpFamilyStmt(from);
3417 case T_AlterOpFamilyStmt:
3418 retval = _copyAlterOpFamilyStmt(from);
3420 case T_CreatedbStmt:
3421 retval = _copyCreatedbStmt(from);
3423 case T_AlterDatabaseStmt:
3424 retval = _copyAlterDatabaseStmt(from);
3426 case T_AlterDatabaseSetStmt:
3427 retval = _copyAlterDatabaseSetStmt(from);
3430 retval = _copyDropdbStmt(from);
3433 retval = _copyVacuumStmt(from);
3436 retval = _copyExplainStmt(from);
3438 case T_CreateSeqStmt:
3439 retval = _copyCreateSeqStmt(from);
3441 case T_AlterSeqStmt:
3442 retval = _copyAlterSeqStmt(from);
3444 case T_VariableSetStmt:
3445 retval = _copyVariableSetStmt(from);
3447 case T_VariableShowStmt:
3448 retval = _copyVariableShowStmt(from);
3451 retval = _copyDiscardStmt(from);
3453 case T_CreateTableSpaceStmt:
3454 retval = _copyCreateTableSpaceStmt(from);
3456 case T_DropTableSpaceStmt:
3457 retval = _copyDropTableSpaceStmt(from);
3459 case T_CreateTrigStmt:
3460 retval = _copyCreateTrigStmt(from);
3462 case T_DropPropertyStmt:
3463 retval = _copyDropPropertyStmt(from);
3465 case T_CreatePLangStmt:
3466 retval = _copyCreatePLangStmt(from);
3468 case T_DropPLangStmt:
3469 retval = _copyDropPLangStmt(from);
3471 case T_CreateRoleStmt:
3472 retval = _copyCreateRoleStmt(from);
3474 case T_AlterRoleStmt:
3475 retval = _copyAlterRoleStmt(from);
3477 case T_AlterRoleSetStmt:
3478 retval = _copyAlterRoleSetStmt(from);
3480 case T_DropRoleStmt:
3481 retval = _copyDropRoleStmt(from);
3484 retval = _copyLockStmt(from);
3486 case T_ConstraintsSetStmt:
3487 retval = _copyConstraintsSetStmt(from);
3490 retval = _copyReindexStmt(from);
3492 case T_CheckPointStmt:
3493 retval = (void *) makeNode(CheckPointStmt);
3495 case T_CreateSchemaStmt:
3496 retval = _copyCreateSchemaStmt(from);
3498 case T_CreateConversionStmt:
3499 retval = _copyCreateConversionStmt(from);
3501 case T_CreateCastStmt:
3502 retval = _copyCreateCastStmt(from);
3504 case T_DropCastStmt:
3505 retval = _copyDropCastStmt(from);
3508 retval = _copyPrepareStmt(from);
3511 retval = _copyExecuteStmt(from);
3513 case T_DeallocateStmt:
3514 retval = _copyDeallocateStmt(from);
3516 case T_DropOwnedStmt:
3517 retval = _copyDropOwnedStmt(from);
3519 case T_ReassignOwnedStmt:
3520 retval = _copyReassignOwnedStmt(from);
3522 case T_AlterTSDictionaryStmt:
3523 retval = _copyAlterTSDictionaryStmt(from);
3525 case T_AlterTSConfigurationStmt:
3526 retval = _copyAlterTSConfigurationStmt(from);
3530 retval = _copyAExpr(from);
3533 retval = _copyColumnRef(from);
3536 retval = _copyParamRef(from);
3539 retval = _copyAConst(from);
3542 retval = _copyFuncCall(from);
3545 retval = _copyAIndices(from);
3547 case T_A_Indirection:
3548 retval = _copyA_Indirection(from);
3551 retval = _copyA_ArrayExpr(from);
3554 retval = _copyResTarget(from);
3557 retval = _copyTypeCast(from);
3560 retval = _copySortBy(from);
3562 case T_RangeSubselect:
3563 retval = _copyRangeSubselect(from);
3565 case T_RangeFunction:
3566 retval = _copyRangeFunction(from);
3569 retval = _copyTypeName(from);
3572 retval = _copyIndexElem(from);
3575 retval = _copyColumnDef(from);
3578 retval = _copyConstraint(from);
3581 retval = _copyDefElem(from);
3583 case T_LockingClause:
3584 retval = _copyLockingClause(from);
3586 case T_RangeTblEntry:
3587 retval = _copyRangeTblEntry(from);
3590 retval = _copySortClause(from);
3593 retval = _copyGroupClause(from);
3595 case T_RowMarkClause:
3596 retval = _copyRowMarkClause(from);
3598 case T_FkConstraint:
3599 retval = _copyFkConstraint(from);
3602 retval = _copyPrivGrantee(from);
3604 case T_FuncWithArgs:
3605 retval = _copyFuncWithArgs(from);
3607 case T_XmlSerialize:
3608 retval = _copyXmlSerialize(from);
3612 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3613 retval = from; /* keep compiler quiet */