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.399 2008/08/07 19:35:02 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(strategy);
656 COPY_SCALAR_FIELD(numCols);
657 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
658 COPY_POINTER_FIELD(dupOperators, from->numCols * sizeof(Oid));
659 COPY_SCALAR_FIELD(flagColIdx);
660 COPY_SCALAR_FIELD(firstFlag);
661 COPY_SCALAR_FIELD(numGroups);
670 _copyLimit(Limit *from)
672 Limit *newnode = makeNode(Limit);
675 * copy node superclass fields
677 CopyPlanFields((Plan *) from, (Plan *) newnode);
680 * copy remainder of node
682 COPY_NODE_FIELD(limitOffset);
683 COPY_NODE_FIELD(limitCount);
688 /* ****************************************************************
689 * primnodes.h copy functions
690 * ****************************************************************
697 _copyAlias(Alias *from)
699 Alias *newnode = makeNode(Alias);
701 COPY_STRING_FIELD(aliasname);
702 COPY_NODE_FIELD(colnames);
711 _copyRangeVar(RangeVar *from)
713 RangeVar *newnode = makeNode(RangeVar);
715 COPY_STRING_FIELD(catalogname);
716 COPY_STRING_FIELD(schemaname);
717 COPY_STRING_FIELD(relname);
718 COPY_SCALAR_FIELD(inhOpt);
719 COPY_SCALAR_FIELD(istemp);
720 COPY_NODE_FIELD(alias);
729 _copyIntoClause(IntoClause *from)
731 IntoClause *newnode = makeNode(IntoClause);
733 COPY_NODE_FIELD(rel);
734 COPY_NODE_FIELD(colNames);
735 COPY_NODE_FIELD(options);
736 COPY_SCALAR_FIELD(onCommit);
737 COPY_STRING_FIELD(tableSpaceName);
743 * We don't need a _copyExpr because Expr is an abstract supertype which
744 * should never actually get instantiated. Also, since it has no common
745 * fields except NodeTag, there's no need for a helper routine to factor
746 * out copying the common fields...
755 Var *newnode = makeNode(Var);
757 COPY_SCALAR_FIELD(varno);
758 COPY_SCALAR_FIELD(varattno);
759 COPY_SCALAR_FIELD(vartype);
760 COPY_SCALAR_FIELD(vartypmod);
761 COPY_SCALAR_FIELD(varlevelsup);
762 COPY_SCALAR_FIELD(varnoold);
763 COPY_SCALAR_FIELD(varoattno);
772 _copyConst(Const *from)
774 Const *newnode = makeNode(Const);
776 COPY_SCALAR_FIELD(consttype);
777 COPY_SCALAR_FIELD(consttypmod);
778 COPY_SCALAR_FIELD(constlen);
780 if (from->constbyval || from->constisnull)
783 * passed by value so just copy the datum. Also, don't try to copy
784 * struct when value is null!
786 newnode->constvalue = from->constvalue;
791 * passed by reference. We need a palloc'd copy.
793 newnode->constvalue = datumCopy(from->constvalue,
798 COPY_SCALAR_FIELD(constisnull);
799 COPY_SCALAR_FIELD(constbyval);
808 _copyParam(Param *from)
810 Param *newnode = makeNode(Param);
812 COPY_SCALAR_FIELD(paramkind);
813 COPY_SCALAR_FIELD(paramid);
814 COPY_SCALAR_FIELD(paramtype);
815 COPY_SCALAR_FIELD(paramtypmod);
824 _copyAggref(Aggref *from)
826 Aggref *newnode = makeNode(Aggref);
828 COPY_SCALAR_FIELD(aggfnoid);
829 COPY_SCALAR_FIELD(aggtype);
830 COPY_NODE_FIELD(args);
831 COPY_SCALAR_FIELD(agglevelsup);
832 COPY_SCALAR_FIELD(aggstar);
833 COPY_SCALAR_FIELD(aggdistinct);
842 _copyArrayRef(ArrayRef *from)
844 ArrayRef *newnode = makeNode(ArrayRef);
846 COPY_SCALAR_FIELD(refarraytype);
847 COPY_SCALAR_FIELD(refelemtype);
848 COPY_SCALAR_FIELD(reftypmod);
849 COPY_NODE_FIELD(refupperindexpr);
850 COPY_NODE_FIELD(reflowerindexpr);
851 COPY_NODE_FIELD(refexpr);
852 COPY_NODE_FIELD(refassgnexpr);
861 _copyFuncExpr(FuncExpr *from)
863 FuncExpr *newnode = makeNode(FuncExpr);
865 COPY_SCALAR_FIELD(funcid);
866 COPY_SCALAR_FIELD(funcresulttype);
867 COPY_SCALAR_FIELD(funcretset);
868 COPY_SCALAR_FIELD(funcformat);
869 COPY_NODE_FIELD(args);
878 _copyOpExpr(OpExpr *from)
880 OpExpr *newnode = makeNode(OpExpr);
882 COPY_SCALAR_FIELD(opno);
883 COPY_SCALAR_FIELD(opfuncid);
884 COPY_SCALAR_FIELD(opresulttype);
885 COPY_SCALAR_FIELD(opretset);
886 COPY_NODE_FIELD(args);
892 * _copyDistinctExpr (same as OpExpr)
894 static DistinctExpr *
895 _copyDistinctExpr(DistinctExpr *from)
897 DistinctExpr *newnode = makeNode(DistinctExpr);
899 COPY_SCALAR_FIELD(opno);
900 COPY_SCALAR_FIELD(opfuncid);
901 COPY_SCALAR_FIELD(opresulttype);
902 COPY_SCALAR_FIELD(opretset);
903 COPY_NODE_FIELD(args);
909 * _copyScalarArrayOpExpr
911 static ScalarArrayOpExpr *
912 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
914 ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
916 COPY_SCALAR_FIELD(opno);
917 COPY_SCALAR_FIELD(opfuncid);
918 COPY_SCALAR_FIELD(useOr);
919 COPY_NODE_FIELD(args);
928 _copyBoolExpr(BoolExpr *from)
930 BoolExpr *newnode = makeNode(BoolExpr);
932 COPY_SCALAR_FIELD(boolop);
933 COPY_NODE_FIELD(args);
942 _copySubLink(SubLink *from)
944 SubLink *newnode = makeNode(SubLink);
946 COPY_SCALAR_FIELD(subLinkType);
947 COPY_NODE_FIELD(testexpr);
948 COPY_NODE_FIELD(operName);
949 COPY_NODE_FIELD(subselect);
958 _copySubPlan(SubPlan *from)
960 SubPlan *newnode = makeNode(SubPlan);
962 COPY_SCALAR_FIELD(subLinkType);
963 COPY_NODE_FIELD(testexpr);
964 COPY_NODE_FIELD(paramIds);
965 COPY_SCALAR_FIELD(plan_id);
966 COPY_SCALAR_FIELD(firstColType);
967 COPY_SCALAR_FIELD(useHashTable);
968 COPY_SCALAR_FIELD(unknownEqFalse);
969 COPY_NODE_FIELD(setParam);
970 COPY_NODE_FIELD(parParam);
971 COPY_NODE_FIELD(args);
980 _copyFieldSelect(FieldSelect *from)
982 FieldSelect *newnode = makeNode(FieldSelect);
984 COPY_NODE_FIELD(arg);
985 COPY_SCALAR_FIELD(fieldnum);
986 COPY_SCALAR_FIELD(resulttype);
987 COPY_SCALAR_FIELD(resulttypmod);
996 _copyFieldStore(FieldStore *from)
998 FieldStore *newnode = makeNode(FieldStore);
1000 COPY_NODE_FIELD(arg);
1001 COPY_NODE_FIELD(newvals);
1002 COPY_NODE_FIELD(fieldnums);
1003 COPY_SCALAR_FIELD(resulttype);
1011 static RelabelType *
1012 _copyRelabelType(RelabelType *from)
1014 RelabelType *newnode = makeNode(RelabelType);
1016 COPY_NODE_FIELD(arg);
1017 COPY_SCALAR_FIELD(resulttype);
1018 COPY_SCALAR_FIELD(resulttypmod);
1019 COPY_SCALAR_FIELD(relabelformat);
1027 static CoerceViaIO *
1028 _copyCoerceViaIO(CoerceViaIO *from)
1030 CoerceViaIO *newnode = makeNode(CoerceViaIO);
1032 COPY_NODE_FIELD(arg);
1033 COPY_SCALAR_FIELD(resulttype);
1034 COPY_SCALAR_FIELD(coerceformat);
1040 * _copyArrayCoerceExpr
1042 static ArrayCoerceExpr *
1043 _copyArrayCoerceExpr(ArrayCoerceExpr *from)
1045 ArrayCoerceExpr *newnode = makeNode(ArrayCoerceExpr);
1047 COPY_NODE_FIELD(arg);
1048 COPY_SCALAR_FIELD(elemfuncid);
1049 COPY_SCALAR_FIELD(resulttype);
1050 COPY_SCALAR_FIELD(resulttypmod);
1051 COPY_SCALAR_FIELD(isExplicit);
1052 COPY_SCALAR_FIELD(coerceformat);
1058 * _copyConvertRowtypeExpr
1060 static ConvertRowtypeExpr *
1061 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
1063 ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
1065 COPY_NODE_FIELD(arg);
1066 COPY_SCALAR_FIELD(resulttype);
1067 COPY_SCALAR_FIELD(convertformat);
1076 _copyCaseExpr(CaseExpr *from)
1078 CaseExpr *newnode = makeNode(CaseExpr);
1080 COPY_SCALAR_FIELD(casetype);
1081 COPY_NODE_FIELD(arg);
1082 COPY_NODE_FIELD(args);
1083 COPY_NODE_FIELD(defresult);
1092 _copyCaseWhen(CaseWhen *from)
1094 CaseWhen *newnode = makeNode(CaseWhen);
1096 COPY_NODE_FIELD(expr);
1097 COPY_NODE_FIELD(result);
1105 static CaseTestExpr *
1106 _copyCaseTestExpr(CaseTestExpr *from)
1108 CaseTestExpr *newnode = makeNode(CaseTestExpr);
1110 COPY_SCALAR_FIELD(typeId);
1111 COPY_SCALAR_FIELD(typeMod);
1120 _copyArrayExpr(ArrayExpr *from)
1122 ArrayExpr *newnode = makeNode(ArrayExpr);
1124 COPY_SCALAR_FIELD(array_typeid);
1125 COPY_SCALAR_FIELD(element_typeid);
1126 COPY_NODE_FIELD(elements);
1127 COPY_SCALAR_FIELD(multidims);
1136 _copyRowExpr(RowExpr *from)
1138 RowExpr *newnode = makeNode(RowExpr);
1140 COPY_NODE_FIELD(args);
1141 COPY_SCALAR_FIELD(row_typeid);
1142 COPY_SCALAR_FIELD(row_format);
1148 * _copyRowCompareExpr
1150 static RowCompareExpr *
1151 _copyRowCompareExpr(RowCompareExpr *from)
1153 RowCompareExpr *newnode = makeNode(RowCompareExpr);
1155 COPY_SCALAR_FIELD(rctype);
1156 COPY_NODE_FIELD(opnos);
1157 COPY_NODE_FIELD(opfamilies);
1158 COPY_NODE_FIELD(largs);
1159 COPY_NODE_FIELD(rargs);
1167 static CoalesceExpr *
1168 _copyCoalesceExpr(CoalesceExpr *from)
1170 CoalesceExpr *newnode = makeNode(CoalesceExpr);
1172 COPY_SCALAR_FIELD(coalescetype);
1173 COPY_NODE_FIELD(args);
1182 _copyMinMaxExpr(MinMaxExpr *from)
1184 MinMaxExpr *newnode = makeNode(MinMaxExpr);
1186 COPY_SCALAR_FIELD(minmaxtype);
1187 COPY_SCALAR_FIELD(op);
1188 COPY_NODE_FIELD(args);
1197 _copyXmlExpr(XmlExpr *from)
1199 XmlExpr *newnode = makeNode(XmlExpr);
1201 COPY_SCALAR_FIELD(op);
1202 COPY_STRING_FIELD(name);
1203 COPY_NODE_FIELD(named_args);
1204 COPY_NODE_FIELD(arg_names);
1205 COPY_NODE_FIELD(args);
1206 COPY_SCALAR_FIELD(xmloption);
1207 COPY_SCALAR_FIELD(type);
1208 COPY_SCALAR_FIELD(typmod);
1214 * _copyNullIfExpr (same as OpExpr)
1217 _copyNullIfExpr(NullIfExpr *from)
1219 NullIfExpr *newnode = makeNode(NullIfExpr);
1221 COPY_SCALAR_FIELD(opno);
1222 COPY_SCALAR_FIELD(opfuncid);
1223 COPY_SCALAR_FIELD(opresulttype);
1224 COPY_SCALAR_FIELD(opretset);
1225 COPY_NODE_FIELD(args);
1234 _copyNullTest(NullTest *from)
1236 NullTest *newnode = makeNode(NullTest);
1238 COPY_NODE_FIELD(arg);
1239 COPY_SCALAR_FIELD(nulltesttype);
1247 static BooleanTest *
1248 _copyBooleanTest(BooleanTest *from)
1250 BooleanTest *newnode = makeNode(BooleanTest);
1252 COPY_NODE_FIELD(arg);
1253 COPY_SCALAR_FIELD(booltesttype);
1259 * _copyCoerceToDomain
1261 static CoerceToDomain *
1262 _copyCoerceToDomain(CoerceToDomain *from)
1264 CoerceToDomain *newnode = makeNode(CoerceToDomain);
1266 COPY_NODE_FIELD(arg);
1267 COPY_SCALAR_FIELD(resulttype);
1268 COPY_SCALAR_FIELD(resulttypmod);
1269 COPY_SCALAR_FIELD(coercionformat);
1275 * _copyCoerceToDomainValue
1277 static CoerceToDomainValue *
1278 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1280 CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1282 COPY_SCALAR_FIELD(typeId);
1283 COPY_SCALAR_FIELD(typeMod);
1291 static SetToDefault *
1292 _copySetToDefault(SetToDefault *from)
1294 SetToDefault *newnode = makeNode(SetToDefault);
1296 COPY_SCALAR_FIELD(typeId);
1297 COPY_SCALAR_FIELD(typeMod);
1303 * _copyCurrentOfExpr
1305 static CurrentOfExpr *
1306 _copyCurrentOfExpr(CurrentOfExpr *from)
1308 CurrentOfExpr *newnode = makeNode(CurrentOfExpr);
1310 COPY_SCALAR_FIELD(cvarno);
1311 COPY_STRING_FIELD(cursor_name);
1312 COPY_SCALAR_FIELD(cursor_param);
1320 static TargetEntry *
1321 _copyTargetEntry(TargetEntry *from)
1323 TargetEntry *newnode = makeNode(TargetEntry);
1325 COPY_NODE_FIELD(expr);
1326 COPY_SCALAR_FIELD(resno);
1327 COPY_STRING_FIELD(resname);
1328 COPY_SCALAR_FIELD(ressortgroupref);
1329 COPY_SCALAR_FIELD(resorigtbl);
1330 COPY_SCALAR_FIELD(resorigcol);
1331 COPY_SCALAR_FIELD(resjunk);
1339 static RangeTblRef *
1340 _copyRangeTblRef(RangeTblRef *from)
1342 RangeTblRef *newnode = makeNode(RangeTblRef);
1344 COPY_SCALAR_FIELD(rtindex);
1353 _copyJoinExpr(JoinExpr *from)
1355 JoinExpr *newnode = makeNode(JoinExpr);
1357 COPY_SCALAR_FIELD(jointype);
1358 COPY_SCALAR_FIELD(isNatural);
1359 COPY_NODE_FIELD(larg);
1360 COPY_NODE_FIELD(rarg);
1361 COPY_NODE_FIELD(using);
1362 COPY_NODE_FIELD(quals);
1363 COPY_NODE_FIELD(alias);
1364 COPY_SCALAR_FIELD(rtindex);
1373 _copyFromExpr(FromExpr *from)
1375 FromExpr *newnode = makeNode(FromExpr);
1377 COPY_NODE_FIELD(fromlist);
1378 COPY_NODE_FIELD(quals);
1383 /* ****************************************************************
1384 * relation.h copy functions
1386 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1387 * There are some subsidiary structs that are useful to copy, though.
1388 * ****************************************************************
1395 _copyPathKey(PathKey *from)
1397 PathKey *newnode = makeNode(PathKey);
1399 /* EquivalenceClasses are never moved, so just shallow-copy the pointer */
1400 COPY_SCALAR_FIELD(pk_eclass);
1401 COPY_SCALAR_FIELD(pk_opfamily);
1402 COPY_SCALAR_FIELD(pk_strategy);
1403 COPY_SCALAR_FIELD(pk_nulls_first);
1411 static RestrictInfo *
1412 _copyRestrictInfo(RestrictInfo *from)
1414 RestrictInfo *newnode = makeNode(RestrictInfo);
1416 COPY_NODE_FIELD(clause);
1417 COPY_SCALAR_FIELD(is_pushed_down);
1418 COPY_SCALAR_FIELD(outerjoin_delayed);
1419 COPY_SCALAR_FIELD(can_join);
1420 COPY_SCALAR_FIELD(pseudoconstant);
1421 COPY_BITMAPSET_FIELD(clause_relids);
1422 COPY_BITMAPSET_FIELD(required_relids);
1423 COPY_BITMAPSET_FIELD(left_relids);
1424 COPY_BITMAPSET_FIELD(right_relids);
1425 COPY_NODE_FIELD(orclause);
1426 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1427 COPY_SCALAR_FIELD(parent_ec);
1428 COPY_SCALAR_FIELD(eval_cost);
1429 COPY_SCALAR_FIELD(this_selec);
1430 COPY_NODE_FIELD(mergeopfamilies);
1431 /* EquivalenceClasses are never copied, so shallow-copy the pointers */
1432 COPY_SCALAR_FIELD(left_ec);
1433 COPY_SCALAR_FIELD(right_ec);
1434 COPY_SCALAR_FIELD(left_em);
1435 COPY_SCALAR_FIELD(right_em);
1436 /* MergeScanSelCache isn't a Node, so hard to copy; just reset cache */
1437 newnode->scansel_cache = NIL;
1438 COPY_SCALAR_FIELD(outer_is_left);
1439 COPY_SCALAR_FIELD(hashjoinoperator);
1440 COPY_SCALAR_FIELD(left_bucketsize);
1441 COPY_SCALAR_FIELD(right_bucketsize);
1447 * _copyOuterJoinInfo
1449 static OuterJoinInfo *
1450 _copyOuterJoinInfo(OuterJoinInfo *from)
1452 OuterJoinInfo *newnode = makeNode(OuterJoinInfo);
1454 COPY_BITMAPSET_FIELD(min_lefthand);
1455 COPY_BITMAPSET_FIELD(min_righthand);
1456 COPY_BITMAPSET_FIELD(syn_lefthand);
1457 COPY_BITMAPSET_FIELD(syn_righthand);
1458 COPY_SCALAR_FIELD(is_full_join);
1459 COPY_SCALAR_FIELD(lhs_strict);
1460 COPY_SCALAR_FIELD(delay_upper_joins);
1468 static InClauseInfo *
1469 _copyInClauseInfo(InClauseInfo *from)
1471 InClauseInfo *newnode = makeNode(InClauseInfo);
1473 COPY_BITMAPSET_FIELD(lefthand);
1474 COPY_BITMAPSET_FIELD(righthand);
1475 COPY_NODE_FIELD(sub_targetlist);
1476 COPY_NODE_FIELD(in_operators);
1482 * _copyAppendRelInfo
1484 static AppendRelInfo *
1485 _copyAppendRelInfo(AppendRelInfo *from)
1487 AppendRelInfo *newnode = makeNode(AppendRelInfo);
1489 COPY_SCALAR_FIELD(parent_relid);
1490 COPY_SCALAR_FIELD(child_relid);
1491 COPY_SCALAR_FIELD(parent_reltype);
1492 COPY_SCALAR_FIELD(child_reltype);
1493 COPY_NODE_FIELD(col_mappings);
1494 COPY_NODE_FIELD(translated_vars);
1495 COPY_SCALAR_FIELD(parent_reloid);
1500 /* ****************************************************************
1501 * parsenodes.h copy functions
1502 * ****************************************************************
1505 static RangeTblEntry *
1506 _copyRangeTblEntry(RangeTblEntry *from)
1508 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1510 COPY_SCALAR_FIELD(rtekind);
1511 COPY_SCALAR_FIELD(relid);
1512 COPY_NODE_FIELD(subquery);
1513 COPY_NODE_FIELD(funcexpr);
1514 COPY_NODE_FIELD(funccoltypes);
1515 COPY_NODE_FIELD(funccoltypmods);
1516 COPY_NODE_FIELD(values_lists);
1517 COPY_SCALAR_FIELD(jointype);
1518 COPY_NODE_FIELD(joinaliasvars);
1519 COPY_NODE_FIELD(alias);
1520 COPY_NODE_FIELD(eref);
1521 COPY_SCALAR_FIELD(inh);
1522 COPY_SCALAR_FIELD(inFromCl);
1523 COPY_SCALAR_FIELD(requiredPerms);
1524 COPY_SCALAR_FIELD(checkAsUser);
1529 static FkConstraint *
1530 _copyFkConstraint(FkConstraint *from)
1532 FkConstraint *newnode = makeNode(FkConstraint);
1534 COPY_STRING_FIELD(constr_name);
1535 COPY_NODE_FIELD(pktable);
1536 COPY_NODE_FIELD(fk_attrs);
1537 COPY_NODE_FIELD(pk_attrs);
1538 COPY_SCALAR_FIELD(fk_matchtype);
1539 COPY_SCALAR_FIELD(fk_upd_action);
1540 COPY_SCALAR_FIELD(fk_del_action);
1541 COPY_SCALAR_FIELD(deferrable);
1542 COPY_SCALAR_FIELD(initdeferred);
1543 COPY_SCALAR_FIELD(skip_validation);
1548 static SortGroupClause *
1549 _copySortGroupClause(SortGroupClause *from)
1551 SortGroupClause *newnode = makeNode(SortGroupClause);
1553 COPY_SCALAR_FIELD(tleSortGroupRef);
1554 COPY_SCALAR_FIELD(eqop);
1555 COPY_SCALAR_FIELD(sortop);
1556 COPY_SCALAR_FIELD(nulls_first);
1561 static RowMarkClause *
1562 _copyRowMarkClause(RowMarkClause *from)
1564 RowMarkClause *newnode = makeNode(RowMarkClause);
1566 COPY_SCALAR_FIELD(rti);
1567 COPY_SCALAR_FIELD(forUpdate);
1568 COPY_SCALAR_FIELD(noWait);
1574 _copyAExpr(A_Expr *from)
1576 A_Expr *newnode = makeNode(A_Expr);
1578 COPY_SCALAR_FIELD(kind);
1579 COPY_NODE_FIELD(name);
1580 COPY_NODE_FIELD(lexpr);
1581 COPY_NODE_FIELD(rexpr);
1582 COPY_SCALAR_FIELD(location);
1588 _copyColumnRef(ColumnRef *from)
1590 ColumnRef *newnode = makeNode(ColumnRef);
1592 COPY_NODE_FIELD(fields);
1593 COPY_SCALAR_FIELD(location);
1599 _copyParamRef(ParamRef *from)
1601 ParamRef *newnode = makeNode(ParamRef);
1603 COPY_SCALAR_FIELD(number);
1609 _copyAConst(A_Const *from)
1611 A_Const *newnode = makeNode(A_Const);
1613 /* This part must duplicate _copyValue */
1614 COPY_SCALAR_FIELD(val.type);
1615 switch (from->val.type)
1618 COPY_SCALAR_FIELD(val.val.ival);
1623 COPY_STRING_FIELD(val.val.str);
1629 elog(ERROR, "unrecognized node type: %d",
1630 (int) from->val.type);
1638 _copyFuncCall(FuncCall *from)
1640 FuncCall *newnode = makeNode(FuncCall);
1642 COPY_NODE_FIELD(funcname);
1643 COPY_NODE_FIELD(args);
1644 COPY_SCALAR_FIELD(agg_star);
1645 COPY_SCALAR_FIELD(agg_distinct);
1646 COPY_SCALAR_FIELD(func_variadic);
1647 COPY_SCALAR_FIELD(location);
1653 _copyAIndices(A_Indices *from)
1655 A_Indices *newnode = makeNode(A_Indices);
1657 COPY_NODE_FIELD(lidx);
1658 COPY_NODE_FIELD(uidx);
1663 static A_Indirection *
1664 _copyA_Indirection(A_Indirection *from)
1666 A_Indirection *newnode = makeNode(A_Indirection);
1668 COPY_NODE_FIELD(arg);
1669 COPY_NODE_FIELD(indirection);
1674 static A_ArrayExpr *
1675 _copyA_ArrayExpr(A_ArrayExpr *from)
1677 A_ArrayExpr *newnode = makeNode(A_ArrayExpr);
1679 COPY_NODE_FIELD(elements);
1685 _copyResTarget(ResTarget *from)
1687 ResTarget *newnode = makeNode(ResTarget);
1689 COPY_STRING_FIELD(name);
1690 COPY_NODE_FIELD(indirection);
1691 COPY_NODE_FIELD(val);
1692 COPY_SCALAR_FIELD(location);
1698 _copyTypeName(TypeName *from)
1700 TypeName *newnode = makeNode(TypeName);
1702 COPY_NODE_FIELD(names);
1703 COPY_SCALAR_FIELD(typeid);
1704 COPY_SCALAR_FIELD(setof);
1705 COPY_SCALAR_FIELD(pct_type);
1706 COPY_NODE_FIELD(typmods);
1707 COPY_SCALAR_FIELD(typemod);
1708 COPY_NODE_FIELD(arrayBounds);
1709 COPY_SCALAR_FIELD(location);
1715 _copySortBy(SortBy *from)
1717 SortBy *newnode = makeNode(SortBy);
1719 COPY_SCALAR_FIELD(sortby_dir);
1720 COPY_SCALAR_FIELD(sortby_nulls);
1721 COPY_NODE_FIELD(useOp);
1722 COPY_NODE_FIELD(node);
1727 static RangeSubselect *
1728 _copyRangeSubselect(RangeSubselect *from)
1730 RangeSubselect *newnode = makeNode(RangeSubselect);
1732 COPY_NODE_FIELD(subquery);
1733 COPY_NODE_FIELD(alias);
1738 static RangeFunction *
1739 _copyRangeFunction(RangeFunction *from)
1741 RangeFunction *newnode = makeNode(RangeFunction);
1743 COPY_NODE_FIELD(funccallnode);
1744 COPY_NODE_FIELD(alias);
1745 COPY_NODE_FIELD(coldeflist);
1751 _copyTypeCast(TypeCast *from)
1753 TypeCast *newnode = makeNode(TypeCast);
1755 COPY_NODE_FIELD(arg);
1756 COPY_NODE_FIELD(typename);
1762 _copyIndexElem(IndexElem *from)
1764 IndexElem *newnode = makeNode(IndexElem);
1766 COPY_STRING_FIELD(name);
1767 COPY_NODE_FIELD(expr);
1768 COPY_NODE_FIELD(opclass);
1769 COPY_SCALAR_FIELD(ordering);
1770 COPY_SCALAR_FIELD(nulls_ordering);
1776 _copyColumnDef(ColumnDef *from)
1778 ColumnDef *newnode = makeNode(ColumnDef);
1780 COPY_STRING_FIELD(colname);
1781 COPY_NODE_FIELD(typename);
1782 COPY_SCALAR_FIELD(inhcount);
1783 COPY_SCALAR_FIELD(is_local);
1784 COPY_SCALAR_FIELD(is_not_null);
1785 COPY_NODE_FIELD(raw_default);
1786 COPY_STRING_FIELD(cooked_default);
1787 COPY_NODE_FIELD(constraints);
1793 _copyConstraint(Constraint *from)
1795 Constraint *newnode = makeNode(Constraint);
1797 COPY_SCALAR_FIELD(contype);
1798 COPY_STRING_FIELD(name);
1799 COPY_NODE_FIELD(raw_expr);
1800 COPY_STRING_FIELD(cooked_expr);
1801 COPY_NODE_FIELD(keys);
1802 COPY_NODE_FIELD(options);
1803 COPY_STRING_FIELD(indexspace);
1809 _copyDefElem(DefElem *from)
1811 DefElem *newnode = makeNode(DefElem);
1813 COPY_STRING_FIELD(defname);
1814 COPY_NODE_FIELD(arg);
1819 static LockingClause *
1820 _copyLockingClause(LockingClause *from)
1822 LockingClause *newnode = makeNode(LockingClause);
1824 COPY_NODE_FIELD(lockedRels);
1825 COPY_SCALAR_FIELD(forUpdate);
1826 COPY_SCALAR_FIELD(noWait);
1831 static XmlSerialize *
1832 _copyXmlSerialize(XmlSerialize *from)
1834 XmlSerialize *newnode = makeNode(XmlSerialize);
1836 COPY_SCALAR_FIELD(xmloption);
1837 COPY_NODE_FIELD(expr);
1838 COPY_NODE_FIELD(typename);
1844 _copyQuery(Query *from)
1846 Query *newnode = makeNode(Query);
1848 COPY_SCALAR_FIELD(commandType);
1849 COPY_SCALAR_FIELD(querySource);
1850 COPY_SCALAR_FIELD(canSetTag);
1851 COPY_NODE_FIELD(utilityStmt);
1852 COPY_SCALAR_FIELD(resultRelation);
1853 COPY_NODE_FIELD(intoClause);
1854 COPY_SCALAR_FIELD(hasAggs);
1855 COPY_SCALAR_FIELD(hasSubLinks);
1856 COPY_SCALAR_FIELD(hasDistinctOn);
1857 COPY_NODE_FIELD(rtable);
1858 COPY_NODE_FIELD(jointree);
1859 COPY_NODE_FIELD(targetList);
1860 COPY_NODE_FIELD(returningList);
1861 COPY_NODE_FIELD(groupClause);
1862 COPY_NODE_FIELD(havingQual);
1863 COPY_NODE_FIELD(distinctClause);
1864 COPY_NODE_FIELD(sortClause);
1865 COPY_NODE_FIELD(limitOffset);
1866 COPY_NODE_FIELD(limitCount);
1867 COPY_NODE_FIELD(rowMarks);
1868 COPY_NODE_FIELD(setOperations);
1874 _copyInsertStmt(InsertStmt *from)
1876 InsertStmt *newnode = makeNode(InsertStmt);
1878 COPY_NODE_FIELD(relation);
1879 COPY_NODE_FIELD(cols);
1880 COPY_NODE_FIELD(selectStmt);
1881 COPY_NODE_FIELD(returningList);
1887 _copyDeleteStmt(DeleteStmt *from)
1889 DeleteStmt *newnode = makeNode(DeleteStmt);
1891 COPY_NODE_FIELD(relation);
1892 COPY_NODE_FIELD(usingClause);
1893 COPY_NODE_FIELD(whereClause);
1894 COPY_NODE_FIELD(returningList);
1900 _copyUpdateStmt(UpdateStmt *from)
1902 UpdateStmt *newnode = makeNode(UpdateStmt);
1904 COPY_NODE_FIELD(relation);
1905 COPY_NODE_FIELD(targetList);
1906 COPY_NODE_FIELD(whereClause);
1907 COPY_NODE_FIELD(fromClause);
1908 COPY_NODE_FIELD(returningList);
1914 _copySelectStmt(SelectStmt *from)
1916 SelectStmt *newnode = makeNode(SelectStmt);
1918 COPY_NODE_FIELD(distinctClause);
1919 COPY_NODE_FIELD(intoClause);
1920 COPY_NODE_FIELD(targetList);
1921 COPY_NODE_FIELD(fromClause);
1922 COPY_NODE_FIELD(whereClause);
1923 COPY_NODE_FIELD(groupClause);
1924 COPY_NODE_FIELD(havingClause);
1925 COPY_NODE_FIELD(valuesLists);
1926 COPY_NODE_FIELD(sortClause);
1927 COPY_NODE_FIELD(limitOffset);
1928 COPY_NODE_FIELD(limitCount);
1929 COPY_NODE_FIELD(lockingClause);
1930 COPY_SCALAR_FIELD(op);
1931 COPY_SCALAR_FIELD(all);
1932 COPY_NODE_FIELD(larg);
1933 COPY_NODE_FIELD(rarg);
1938 static SetOperationStmt *
1939 _copySetOperationStmt(SetOperationStmt *from)
1941 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1943 COPY_SCALAR_FIELD(op);
1944 COPY_SCALAR_FIELD(all);
1945 COPY_NODE_FIELD(larg);
1946 COPY_NODE_FIELD(rarg);
1947 COPY_NODE_FIELD(colTypes);
1948 COPY_NODE_FIELD(colTypmods);
1949 COPY_NODE_FIELD(groupClauses);
1954 static AlterTableStmt *
1955 _copyAlterTableStmt(AlterTableStmt *from)
1957 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1959 COPY_NODE_FIELD(relation);
1960 COPY_NODE_FIELD(cmds);
1961 COPY_SCALAR_FIELD(relkind);
1966 static AlterTableCmd *
1967 _copyAlterTableCmd(AlterTableCmd *from)
1969 AlterTableCmd *newnode = makeNode(AlterTableCmd);
1971 COPY_SCALAR_FIELD(subtype);
1972 COPY_STRING_FIELD(name);
1973 COPY_NODE_FIELD(def);
1974 COPY_NODE_FIELD(transform);
1975 COPY_SCALAR_FIELD(behavior);
1980 static AlterDomainStmt *
1981 _copyAlterDomainStmt(AlterDomainStmt *from)
1983 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1985 COPY_SCALAR_FIELD(subtype);
1986 COPY_NODE_FIELD(typename);
1987 COPY_STRING_FIELD(name);
1988 COPY_NODE_FIELD(def);
1989 COPY_SCALAR_FIELD(behavior);
1995 _copyGrantStmt(GrantStmt *from)
1997 GrantStmt *newnode = makeNode(GrantStmt);
1999 COPY_SCALAR_FIELD(is_grant);
2000 COPY_SCALAR_FIELD(objtype);
2001 COPY_NODE_FIELD(objects);
2002 COPY_NODE_FIELD(privileges);
2003 COPY_NODE_FIELD(grantees);
2004 COPY_SCALAR_FIELD(grant_option);
2005 COPY_SCALAR_FIELD(behavior);
2010 static PrivGrantee *
2011 _copyPrivGrantee(PrivGrantee *from)
2013 PrivGrantee *newnode = makeNode(PrivGrantee);
2015 COPY_STRING_FIELD(rolname);
2020 static FuncWithArgs *
2021 _copyFuncWithArgs(FuncWithArgs *from)
2023 FuncWithArgs *newnode = makeNode(FuncWithArgs);
2025 COPY_NODE_FIELD(funcname);
2026 COPY_NODE_FIELD(funcargs);
2031 static GrantRoleStmt *
2032 _copyGrantRoleStmt(GrantRoleStmt *from)
2034 GrantRoleStmt *newnode = makeNode(GrantRoleStmt);
2036 COPY_NODE_FIELD(granted_roles);
2037 COPY_NODE_FIELD(grantee_roles);
2038 COPY_SCALAR_FIELD(is_grant);
2039 COPY_SCALAR_FIELD(admin_opt);
2040 COPY_STRING_FIELD(grantor);
2041 COPY_SCALAR_FIELD(behavior);
2046 static DeclareCursorStmt *
2047 _copyDeclareCursorStmt(DeclareCursorStmt *from)
2049 DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
2051 COPY_STRING_FIELD(portalname);
2052 COPY_SCALAR_FIELD(options);
2053 COPY_NODE_FIELD(query);
2058 static ClosePortalStmt *
2059 _copyClosePortalStmt(ClosePortalStmt *from)
2061 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
2063 COPY_STRING_FIELD(portalname);
2068 static ClusterStmt *
2069 _copyClusterStmt(ClusterStmt *from)
2071 ClusterStmt *newnode = makeNode(ClusterStmt);
2073 COPY_NODE_FIELD(relation);
2074 COPY_STRING_FIELD(indexname);
2080 _copyCopyStmt(CopyStmt *from)
2082 CopyStmt *newnode = makeNode(CopyStmt);
2084 COPY_NODE_FIELD(relation);
2085 COPY_NODE_FIELD(query);
2086 COPY_NODE_FIELD(attlist);
2087 COPY_SCALAR_FIELD(is_from);
2088 COPY_STRING_FIELD(filename);
2089 COPY_NODE_FIELD(options);
2095 _copyCreateStmt(CreateStmt *from)
2097 CreateStmt *newnode = makeNode(CreateStmt);
2099 COPY_NODE_FIELD(relation);
2100 COPY_NODE_FIELD(tableElts);
2101 COPY_NODE_FIELD(inhRelations);
2102 COPY_NODE_FIELD(constraints);
2103 COPY_NODE_FIELD(options);
2104 COPY_SCALAR_FIELD(oncommit);
2105 COPY_STRING_FIELD(tablespacename);
2110 static InhRelation *
2111 _copyInhRelation(InhRelation *from)
2113 InhRelation *newnode = makeNode(InhRelation);
2115 COPY_NODE_FIELD(relation);
2116 COPY_NODE_FIELD(options);
2122 _copyDefineStmt(DefineStmt *from)
2124 DefineStmt *newnode = makeNode(DefineStmt);
2126 COPY_SCALAR_FIELD(kind);
2127 COPY_SCALAR_FIELD(oldstyle);
2128 COPY_NODE_FIELD(defnames);
2129 COPY_NODE_FIELD(args);
2130 COPY_NODE_FIELD(definition);
2136 _copyDropStmt(DropStmt *from)
2138 DropStmt *newnode = makeNode(DropStmt);
2140 COPY_NODE_FIELD(objects);
2141 COPY_SCALAR_FIELD(removeType);
2142 COPY_SCALAR_FIELD(behavior);
2143 COPY_SCALAR_FIELD(missing_ok);
2148 static TruncateStmt *
2149 _copyTruncateStmt(TruncateStmt *from)
2151 TruncateStmt *newnode = makeNode(TruncateStmt);
2153 COPY_NODE_FIELD(relations);
2154 COPY_SCALAR_FIELD(restart_seqs);
2155 COPY_SCALAR_FIELD(behavior);
2160 static CommentStmt *
2161 _copyCommentStmt(CommentStmt *from)
2163 CommentStmt *newnode = makeNode(CommentStmt);
2165 COPY_SCALAR_FIELD(objtype);
2166 COPY_NODE_FIELD(objname);
2167 COPY_NODE_FIELD(objargs);
2168 COPY_STRING_FIELD(comment);
2174 _copyFetchStmt(FetchStmt *from)
2176 FetchStmt *newnode = makeNode(FetchStmt);
2178 COPY_SCALAR_FIELD(direction);
2179 COPY_SCALAR_FIELD(howMany);
2180 COPY_STRING_FIELD(portalname);
2181 COPY_SCALAR_FIELD(ismove);
2187 _copyIndexStmt(IndexStmt *from)
2189 IndexStmt *newnode = makeNode(IndexStmt);
2191 COPY_STRING_FIELD(idxname);
2192 COPY_NODE_FIELD(relation);
2193 COPY_STRING_FIELD(accessMethod);
2194 COPY_STRING_FIELD(tableSpace);
2195 COPY_NODE_FIELD(indexParams);
2196 COPY_NODE_FIELD(options);
2197 COPY_NODE_FIELD(whereClause);
2198 COPY_SCALAR_FIELD(unique);
2199 COPY_SCALAR_FIELD(primary);
2200 COPY_SCALAR_FIELD(isconstraint);
2201 COPY_SCALAR_FIELD(concurrent);
2206 static CreateFunctionStmt *
2207 _copyCreateFunctionStmt(CreateFunctionStmt *from)
2209 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
2211 COPY_SCALAR_FIELD(replace);
2212 COPY_NODE_FIELD(funcname);
2213 COPY_NODE_FIELD(parameters);
2214 COPY_NODE_FIELD(returnType);
2215 COPY_NODE_FIELD(options);
2216 COPY_NODE_FIELD(withClause);
2221 static FunctionParameter *
2222 _copyFunctionParameter(FunctionParameter *from)
2224 FunctionParameter *newnode = makeNode(FunctionParameter);
2226 COPY_STRING_FIELD(name);
2227 COPY_NODE_FIELD(argType);
2228 COPY_SCALAR_FIELD(mode);
2233 static AlterFunctionStmt *
2234 _copyAlterFunctionStmt(AlterFunctionStmt *from)
2236 AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
2238 COPY_NODE_FIELD(func);
2239 COPY_NODE_FIELD(actions);
2244 static RemoveFuncStmt *
2245 _copyRemoveFuncStmt(RemoveFuncStmt *from)
2247 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
2249 COPY_SCALAR_FIELD(kind);
2250 COPY_NODE_FIELD(name);
2251 COPY_NODE_FIELD(args);
2252 COPY_SCALAR_FIELD(behavior);
2253 COPY_SCALAR_FIELD(missing_ok);
2258 static RemoveOpClassStmt *
2259 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2261 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2263 COPY_NODE_FIELD(opclassname);
2264 COPY_STRING_FIELD(amname);
2265 COPY_SCALAR_FIELD(behavior);
2266 COPY_SCALAR_FIELD(missing_ok);
2271 static RemoveOpFamilyStmt *
2272 _copyRemoveOpFamilyStmt(RemoveOpFamilyStmt *from)
2274 RemoveOpFamilyStmt *newnode = makeNode(RemoveOpFamilyStmt);
2276 COPY_NODE_FIELD(opfamilyname);
2277 COPY_STRING_FIELD(amname);
2278 COPY_SCALAR_FIELD(behavior);
2279 COPY_SCALAR_FIELD(missing_ok);
2285 _copyRenameStmt(RenameStmt *from)
2287 RenameStmt *newnode = makeNode(RenameStmt);
2289 COPY_SCALAR_FIELD(renameType);
2290 COPY_NODE_FIELD(relation);
2291 COPY_NODE_FIELD(object);
2292 COPY_NODE_FIELD(objarg);
2293 COPY_STRING_FIELD(subname);
2294 COPY_STRING_FIELD(newname);
2299 static AlterObjectSchemaStmt *
2300 _copyAlterObjectSchemaStmt(AlterObjectSchemaStmt *from)
2302 AlterObjectSchemaStmt *newnode = makeNode(AlterObjectSchemaStmt);
2304 COPY_SCALAR_FIELD(objectType);
2305 COPY_NODE_FIELD(relation);
2306 COPY_NODE_FIELD(object);
2307 COPY_NODE_FIELD(objarg);
2308 COPY_STRING_FIELD(addname);
2309 COPY_STRING_FIELD(newschema);
2314 static AlterOwnerStmt *
2315 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2317 AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2319 COPY_SCALAR_FIELD(objectType);
2320 COPY_NODE_FIELD(relation);
2321 COPY_NODE_FIELD(object);
2322 COPY_NODE_FIELD(objarg);
2323 COPY_STRING_FIELD(addname);
2324 COPY_STRING_FIELD(newowner);
2330 _copyRuleStmt(RuleStmt *from)
2332 RuleStmt *newnode = makeNode(RuleStmt);
2334 COPY_NODE_FIELD(relation);
2335 COPY_STRING_FIELD(rulename);
2336 COPY_NODE_FIELD(whereClause);
2337 COPY_SCALAR_FIELD(event);
2338 COPY_SCALAR_FIELD(instead);
2339 COPY_NODE_FIELD(actions);
2340 COPY_SCALAR_FIELD(replace);
2346 _copyNotifyStmt(NotifyStmt *from)
2348 NotifyStmt *newnode = makeNode(NotifyStmt);
2350 COPY_NODE_FIELD(relation);
2356 _copyListenStmt(ListenStmt *from)
2358 ListenStmt *newnode = makeNode(ListenStmt);
2360 COPY_NODE_FIELD(relation);
2365 static UnlistenStmt *
2366 _copyUnlistenStmt(UnlistenStmt *from)
2368 UnlistenStmt *newnode = makeNode(UnlistenStmt);
2370 COPY_NODE_FIELD(relation);
2375 static TransactionStmt *
2376 _copyTransactionStmt(TransactionStmt *from)
2378 TransactionStmt *newnode = makeNode(TransactionStmt);
2380 COPY_SCALAR_FIELD(kind);
2381 COPY_NODE_FIELD(options);
2382 COPY_STRING_FIELD(gid);
2387 static CompositeTypeStmt *
2388 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2390 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2392 COPY_NODE_FIELD(typevar);
2393 COPY_NODE_FIELD(coldeflist);
2398 static CreateEnumStmt *
2399 _copyCreateEnumStmt(CreateEnumStmt *from)
2401 CreateEnumStmt *newnode = makeNode(CreateEnumStmt);
2403 COPY_NODE_FIELD(typename);
2404 COPY_NODE_FIELD(vals);
2410 _copyViewStmt(ViewStmt *from)
2412 ViewStmt *newnode = makeNode(ViewStmt);
2414 COPY_NODE_FIELD(view);
2415 COPY_NODE_FIELD(aliases);
2416 COPY_NODE_FIELD(query);
2417 COPY_SCALAR_FIELD(replace);
2423 _copyLoadStmt(LoadStmt *from)
2425 LoadStmt *newnode = makeNode(LoadStmt);
2427 COPY_STRING_FIELD(filename);
2432 static CreateDomainStmt *
2433 _copyCreateDomainStmt(CreateDomainStmt *from)
2435 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2437 COPY_NODE_FIELD(domainname);
2438 COPY_NODE_FIELD(typename);
2439 COPY_NODE_FIELD(constraints);
2444 static CreateOpClassStmt *
2445 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2447 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2449 COPY_NODE_FIELD(opclassname);
2450 COPY_NODE_FIELD(opfamilyname);
2451 COPY_STRING_FIELD(amname);
2452 COPY_NODE_FIELD(datatype);
2453 COPY_NODE_FIELD(items);
2454 COPY_SCALAR_FIELD(isDefault);
2459 static CreateOpClassItem *
2460 _copyCreateOpClassItem(CreateOpClassItem *from)
2462 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2464 COPY_SCALAR_FIELD(itemtype);
2465 COPY_NODE_FIELD(name);
2466 COPY_NODE_FIELD(args);
2467 COPY_SCALAR_FIELD(number);
2468 COPY_NODE_FIELD(class_args);
2469 COPY_NODE_FIELD(storedtype);
2474 static CreateOpFamilyStmt *
2475 _copyCreateOpFamilyStmt(CreateOpFamilyStmt *from)
2477 CreateOpFamilyStmt *newnode = makeNode(CreateOpFamilyStmt);
2479 COPY_NODE_FIELD(opfamilyname);
2480 COPY_STRING_FIELD(amname);
2485 static AlterOpFamilyStmt *
2486 _copyAlterOpFamilyStmt(AlterOpFamilyStmt *from)
2488 AlterOpFamilyStmt *newnode = makeNode(AlterOpFamilyStmt);
2490 COPY_NODE_FIELD(opfamilyname);
2491 COPY_STRING_FIELD(amname);
2492 COPY_SCALAR_FIELD(isDrop);
2493 COPY_NODE_FIELD(items);
2498 static CreatedbStmt *
2499 _copyCreatedbStmt(CreatedbStmt *from)
2501 CreatedbStmt *newnode = makeNode(CreatedbStmt);
2503 COPY_STRING_FIELD(dbname);
2504 COPY_NODE_FIELD(options);
2509 static AlterDatabaseStmt *
2510 _copyAlterDatabaseStmt(AlterDatabaseStmt *from)
2512 AlterDatabaseStmt *newnode = makeNode(AlterDatabaseStmt);
2514 COPY_STRING_FIELD(dbname);
2515 COPY_NODE_FIELD(options);
2520 static AlterDatabaseSetStmt *
2521 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2523 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2525 COPY_STRING_FIELD(dbname);
2526 COPY_NODE_FIELD(setstmt);
2532 _copyDropdbStmt(DropdbStmt *from)
2534 DropdbStmt *newnode = makeNode(DropdbStmt);
2536 COPY_STRING_FIELD(dbname);
2537 COPY_SCALAR_FIELD(missing_ok);
2543 _copyVacuumStmt(VacuumStmt *from)
2545 VacuumStmt *newnode = makeNode(VacuumStmt);
2547 COPY_SCALAR_FIELD(vacuum);
2548 COPY_SCALAR_FIELD(full);
2549 COPY_SCALAR_FIELD(analyze);
2550 COPY_SCALAR_FIELD(verbose);
2551 COPY_SCALAR_FIELD(freeze_min_age);
2552 COPY_NODE_FIELD(relation);
2553 COPY_NODE_FIELD(va_cols);
2558 static ExplainStmt *
2559 _copyExplainStmt(ExplainStmt *from)
2561 ExplainStmt *newnode = makeNode(ExplainStmt);
2563 COPY_NODE_FIELD(query);
2564 COPY_SCALAR_FIELD(verbose);
2565 COPY_SCALAR_FIELD(analyze);
2570 static CreateSeqStmt *
2571 _copyCreateSeqStmt(CreateSeqStmt *from)
2573 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2575 COPY_NODE_FIELD(sequence);
2576 COPY_NODE_FIELD(options);
2581 static AlterSeqStmt *
2582 _copyAlterSeqStmt(AlterSeqStmt *from)
2584 AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2586 COPY_NODE_FIELD(sequence);
2587 COPY_NODE_FIELD(options);
2592 static VariableSetStmt *
2593 _copyVariableSetStmt(VariableSetStmt *from)
2595 VariableSetStmt *newnode = makeNode(VariableSetStmt);
2597 COPY_SCALAR_FIELD(kind);
2598 COPY_STRING_FIELD(name);
2599 COPY_NODE_FIELD(args);
2600 COPY_SCALAR_FIELD(is_local);
2605 static VariableShowStmt *
2606 _copyVariableShowStmt(VariableShowStmt *from)
2608 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2610 COPY_STRING_FIELD(name);
2615 static DiscardStmt *
2616 _copyDiscardStmt(DiscardStmt *from)
2618 DiscardStmt *newnode = makeNode(DiscardStmt);
2620 COPY_SCALAR_FIELD(target);
2625 static CreateTableSpaceStmt *
2626 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2628 CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2630 COPY_STRING_FIELD(tablespacename);
2631 COPY_STRING_FIELD(owner);
2632 COPY_STRING_FIELD(location);
2637 static DropTableSpaceStmt *
2638 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2640 DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2642 COPY_STRING_FIELD(tablespacename);
2643 COPY_SCALAR_FIELD(missing_ok);
2648 static CreateTrigStmt *
2649 _copyCreateTrigStmt(CreateTrigStmt *from)
2651 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2653 COPY_STRING_FIELD(trigname);
2654 COPY_NODE_FIELD(relation);
2655 COPY_NODE_FIELD(funcname);
2656 COPY_NODE_FIELD(args);
2657 COPY_SCALAR_FIELD(before);
2658 COPY_SCALAR_FIELD(row);
2659 strcpy(newnode->actions, from->actions); /* in-line string field */
2660 COPY_SCALAR_FIELD(isconstraint);
2661 COPY_SCALAR_FIELD(deferrable);
2662 COPY_SCALAR_FIELD(initdeferred);
2663 COPY_NODE_FIELD(constrrel);
2668 static DropPropertyStmt *
2669 _copyDropPropertyStmt(DropPropertyStmt *from)
2671 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2673 COPY_NODE_FIELD(relation);
2674 COPY_STRING_FIELD(property);
2675 COPY_SCALAR_FIELD(removeType);
2676 COPY_SCALAR_FIELD(behavior);
2677 COPY_SCALAR_FIELD(missing_ok);
2682 static CreatePLangStmt *
2683 _copyCreatePLangStmt(CreatePLangStmt *from)
2685 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2687 COPY_STRING_FIELD(plname);
2688 COPY_NODE_FIELD(plhandler);
2689 COPY_NODE_FIELD(plvalidator);
2690 COPY_SCALAR_FIELD(pltrusted);
2695 static DropPLangStmt *
2696 _copyDropPLangStmt(DropPLangStmt *from)
2698 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2700 COPY_STRING_FIELD(plname);
2701 COPY_SCALAR_FIELD(behavior);
2702 COPY_SCALAR_FIELD(missing_ok);
2707 static CreateRoleStmt *
2708 _copyCreateRoleStmt(CreateRoleStmt *from)
2710 CreateRoleStmt *newnode = makeNode(CreateRoleStmt);
2712 COPY_SCALAR_FIELD(stmt_type);
2713 COPY_STRING_FIELD(role);
2714 COPY_NODE_FIELD(options);
2719 static AlterRoleStmt *
2720 _copyAlterRoleStmt(AlterRoleStmt *from)
2722 AlterRoleStmt *newnode = makeNode(AlterRoleStmt);
2724 COPY_STRING_FIELD(role);
2725 COPY_NODE_FIELD(options);
2726 COPY_SCALAR_FIELD(action);
2731 static AlterRoleSetStmt *
2732 _copyAlterRoleSetStmt(AlterRoleSetStmt *from)
2734 AlterRoleSetStmt *newnode = makeNode(AlterRoleSetStmt);
2736 COPY_STRING_FIELD(role);
2737 COPY_NODE_FIELD(setstmt);
2742 static DropRoleStmt *
2743 _copyDropRoleStmt(DropRoleStmt *from)
2745 DropRoleStmt *newnode = makeNode(DropRoleStmt);
2747 COPY_NODE_FIELD(roles);
2748 COPY_SCALAR_FIELD(missing_ok);
2754 _copyLockStmt(LockStmt *from)
2756 LockStmt *newnode = makeNode(LockStmt);
2758 COPY_NODE_FIELD(relations);
2759 COPY_SCALAR_FIELD(mode);
2760 COPY_SCALAR_FIELD(nowait);
2765 static ConstraintsSetStmt *
2766 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2768 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2770 COPY_NODE_FIELD(constraints);
2771 COPY_SCALAR_FIELD(deferred);
2776 static ReindexStmt *
2777 _copyReindexStmt(ReindexStmt *from)
2779 ReindexStmt *newnode = makeNode(ReindexStmt);
2781 COPY_SCALAR_FIELD(kind);
2782 COPY_NODE_FIELD(relation);
2783 COPY_STRING_FIELD(name);
2784 COPY_SCALAR_FIELD(do_system);
2785 COPY_SCALAR_FIELD(do_user);
2790 static CreateSchemaStmt *
2791 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2793 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2795 COPY_STRING_FIELD(schemaname);
2796 COPY_STRING_FIELD(authid);
2797 COPY_NODE_FIELD(schemaElts);
2802 static CreateConversionStmt *
2803 _copyCreateConversionStmt(CreateConversionStmt *from)
2805 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2807 COPY_NODE_FIELD(conversion_name);
2808 COPY_STRING_FIELD(for_encoding_name);
2809 COPY_STRING_FIELD(to_encoding_name);
2810 COPY_NODE_FIELD(func_name);
2811 COPY_SCALAR_FIELD(def);
2816 static CreateCastStmt *
2817 _copyCreateCastStmt(CreateCastStmt *from)
2819 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2821 COPY_NODE_FIELD(sourcetype);
2822 COPY_NODE_FIELD(targettype);
2823 COPY_NODE_FIELD(func);
2824 COPY_SCALAR_FIELD(context);
2829 static DropCastStmt *
2830 _copyDropCastStmt(DropCastStmt *from)
2832 DropCastStmt *newnode = makeNode(DropCastStmt);
2834 COPY_NODE_FIELD(sourcetype);
2835 COPY_NODE_FIELD(targettype);
2836 COPY_SCALAR_FIELD(behavior);
2837 COPY_SCALAR_FIELD(missing_ok);
2842 static PrepareStmt *
2843 _copyPrepareStmt(PrepareStmt *from)
2845 PrepareStmt *newnode = makeNode(PrepareStmt);
2847 COPY_STRING_FIELD(name);
2848 COPY_NODE_FIELD(argtypes);
2849 COPY_NODE_FIELD(query);
2854 static ExecuteStmt *
2855 _copyExecuteStmt(ExecuteStmt *from)
2857 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2859 COPY_STRING_FIELD(name);
2860 COPY_NODE_FIELD(into);
2861 COPY_NODE_FIELD(params);
2866 static DeallocateStmt *
2867 _copyDeallocateStmt(DeallocateStmt *from)
2869 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2871 COPY_STRING_FIELD(name);
2876 static DropOwnedStmt *
2877 _copyDropOwnedStmt(DropOwnedStmt *from)
2879 DropOwnedStmt *newnode = makeNode(DropOwnedStmt);
2881 COPY_NODE_FIELD(roles);
2882 COPY_SCALAR_FIELD(behavior);
2887 static ReassignOwnedStmt *
2888 _copyReassignOwnedStmt(ReassignOwnedStmt *from)
2890 ReassignOwnedStmt *newnode = makeNode(ReassignOwnedStmt);
2892 COPY_NODE_FIELD(roles);
2893 COPY_SCALAR_FIELD(newrole);
2898 static AlterTSDictionaryStmt *
2899 _copyAlterTSDictionaryStmt(AlterTSDictionaryStmt *from)
2901 AlterTSDictionaryStmt *newnode = makeNode(AlterTSDictionaryStmt);
2903 COPY_NODE_FIELD(dictname);
2904 COPY_NODE_FIELD(options);
2909 static AlterTSConfigurationStmt *
2910 _copyAlterTSConfigurationStmt(AlterTSConfigurationStmt *from)
2912 AlterTSConfigurationStmt *newnode = makeNode(AlterTSConfigurationStmt);
2914 COPY_NODE_FIELD(cfgname);
2915 COPY_NODE_FIELD(tokentype);
2916 COPY_NODE_FIELD(dicts);
2917 COPY_SCALAR_FIELD(override);
2918 COPY_SCALAR_FIELD(replace);
2919 COPY_SCALAR_FIELD(missing_ok);
2924 /* ****************************************************************
2925 * pg_list.h copy functions
2926 * ****************************************************************
2930 * Perform a deep copy of the specified list, using copyObject(). The
2931 * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2932 * need deep copies, so they should be copied via list_copy()
2934 #define COPY_NODE_CELL(new, old) \
2935 (new) = (ListCell *) palloc(sizeof(ListCell)); \
2936 lfirst(new) = copyObject(lfirst(old));
2939 _copyList(List *from)
2945 Assert(list_length(from) >= 1);
2947 new = makeNode(List);
2948 new->length = from->length;
2950 COPY_NODE_CELL(new->head, from->head);
2951 prev_new = new->head;
2952 curr_old = lnext(from->head);
2956 COPY_NODE_CELL(prev_new->next, curr_old);
2957 prev_new = prev_new->next;
2958 curr_old = curr_old->next;
2960 prev_new->next = NULL;
2961 new->tail = prev_new;
2966 /* ****************************************************************
2967 * value.h copy functions
2968 * ****************************************************************
2971 _copyValue(Value *from)
2973 Value *newnode = makeNode(Value);
2975 /* See also _copyAConst when changing this code! */
2977 COPY_SCALAR_FIELD(type);
2981 COPY_SCALAR_FIELD(val.ival);
2986 COPY_STRING_FIELD(val.str);
2992 elog(ERROR, "unrecognized node type: %d",
3002 * Create a copy of a Node tree or list. This is a "deep" copy: all
3003 * substructure is copied too, recursively.
3006 copyObject(void *from)
3013 switch (nodeTag(from))
3019 retval = _copyPlannedStmt(from);
3022 retval = _copyPlan(from);
3025 retval = _copyResult(from);
3028 retval = _copyAppend(from);
3031 retval = _copyBitmapAnd(from);
3034 retval = _copyBitmapOr(from);
3037 retval = _copyScan(from);
3040 retval = _copySeqScan(from);
3043 retval = _copyIndexScan(from);
3045 case T_BitmapIndexScan:
3046 retval = _copyBitmapIndexScan(from);
3048 case T_BitmapHeapScan:
3049 retval = _copyBitmapHeapScan(from);
3052 retval = _copyTidScan(from);
3054 case T_SubqueryScan:
3055 retval = _copySubqueryScan(from);
3057 case T_FunctionScan:
3058 retval = _copyFunctionScan(from);
3061 retval = _copyValuesScan(from);
3064 retval = _copyJoin(from);
3067 retval = _copyNestLoop(from);
3070 retval = _copyMergeJoin(from);
3073 retval = _copyHashJoin(from);
3076 retval = _copyMaterial(from);
3079 retval = _copySort(from);
3082 retval = _copyGroup(from);
3085 retval = _copyAgg(from);
3088 retval = _copyUnique(from);
3091 retval = _copyHash(from);
3094 retval = _copySetOp(from);
3097 retval = _copyLimit(from);
3104 retval = _copyAlias(from);
3107 retval = _copyRangeVar(from);
3110 retval = _copyIntoClause(from);
3113 retval = _copyVar(from);
3116 retval = _copyConst(from);
3119 retval = _copyParam(from);
3122 retval = _copyAggref(from);
3125 retval = _copyArrayRef(from);
3128 retval = _copyFuncExpr(from);
3131 retval = _copyOpExpr(from);
3133 case T_DistinctExpr:
3134 retval = _copyDistinctExpr(from);
3136 case T_ScalarArrayOpExpr:
3137 retval = _copyScalarArrayOpExpr(from);
3140 retval = _copyBoolExpr(from);
3143 retval = _copySubLink(from);
3146 retval = _copySubPlan(from);
3149 retval = _copyFieldSelect(from);
3152 retval = _copyFieldStore(from);
3155 retval = _copyRelabelType(from);
3158 retval = _copyCoerceViaIO(from);
3160 case T_ArrayCoerceExpr:
3161 retval = _copyArrayCoerceExpr(from);
3163 case T_ConvertRowtypeExpr:
3164 retval = _copyConvertRowtypeExpr(from);
3167 retval = _copyCaseExpr(from);
3170 retval = _copyCaseWhen(from);
3172 case T_CaseTestExpr:
3173 retval = _copyCaseTestExpr(from);
3176 retval = _copyArrayExpr(from);
3179 retval = _copyRowExpr(from);
3181 case T_RowCompareExpr:
3182 retval = _copyRowCompareExpr(from);
3184 case T_CoalesceExpr:
3185 retval = _copyCoalesceExpr(from);
3188 retval = _copyMinMaxExpr(from);
3191 retval = _copyXmlExpr(from);
3194 retval = _copyNullIfExpr(from);
3197 retval = _copyNullTest(from);
3200 retval = _copyBooleanTest(from);
3202 case T_CoerceToDomain:
3203 retval = _copyCoerceToDomain(from);
3205 case T_CoerceToDomainValue:
3206 retval = _copyCoerceToDomainValue(from);
3208 case T_SetToDefault:
3209 retval = _copySetToDefault(from);
3211 case T_CurrentOfExpr:
3212 retval = _copyCurrentOfExpr(from);
3215 retval = _copyTargetEntry(from);
3218 retval = _copyRangeTblRef(from);
3221 retval = _copyJoinExpr(from);
3224 retval = _copyFromExpr(from);
3231 retval = _copyPathKey(from);
3233 case T_RestrictInfo:
3234 retval = _copyRestrictInfo(from);
3236 case T_OuterJoinInfo:
3237 retval = _copyOuterJoinInfo(from);
3239 case T_InClauseInfo:
3240 retval = _copyInClauseInfo(from);
3242 case T_AppendRelInfo:
3243 retval = _copyAppendRelInfo(from);
3254 retval = _copyValue(from);
3261 retval = _copyList(from);
3265 * Lists of integers and OIDs don't need to be deep-copied, so we
3266 * perform a shallow copy via list_copy()
3270 retval = list_copy(from);
3277 retval = _copyQuery(from);
3280 retval = _copyInsertStmt(from);
3283 retval = _copyDeleteStmt(from);
3286 retval = _copyUpdateStmt(from);
3289 retval = _copySelectStmt(from);
3291 case T_SetOperationStmt:
3292 retval = _copySetOperationStmt(from);
3294 case T_AlterTableStmt:
3295 retval = _copyAlterTableStmt(from);
3297 case T_AlterTableCmd:
3298 retval = _copyAlterTableCmd(from);
3300 case T_AlterDomainStmt:
3301 retval = _copyAlterDomainStmt(from);
3304 retval = _copyGrantStmt(from);
3306 case T_GrantRoleStmt:
3307 retval = _copyGrantRoleStmt(from);
3309 case T_DeclareCursorStmt:
3310 retval = _copyDeclareCursorStmt(from);
3312 case T_ClosePortalStmt:
3313 retval = _copyClosePortalStmt(from);
3316 retval = _copyClusterStmt(from);
3319 retval = _copyCopyStmt(from);
3322 retval = _copyCreateStmt(from);
3325 retval = _copyInhRelation(from);
3328 retval = _copyDefineStmt(from);
3331 retval = _copyDropStmt(from);
3333 case T_TruncateStmt:
3334 retval = _copyTruncateStmt(from);
3337 retval = _copyCommentStmt(from);
3340 retval = _copyFetchStmt(from);
3343 retval = _copyIndexStmt(from);
3345 case T_CreateFunctionStmt:
3346 retval = _copyCreateFunctionStmt(from);
3348 case T_FunctionParameter:
3349 retval = _copyFunctionParameter(from);
3351 case T_AlterFunctionStmt:
3352 retval = _copyAlterFunctionStmt(from);
3354 case T_RemoveFuncStmt:
3355 retval = _copyRemoveFuncStmt(from);
3357 case T_RemoveOpClassStmt:
3358 retval = _copyRemoveOpClassStmt(from);
3360 case T_RemoveOpFamilyStmt:
3361 retval = _copyRemoveOpFamilyStmt(from);
3364 retval = _copyRenameStmt(from);
3366 case T_AlterObjectSchemaStmt:
3367 retval = _copyAlterObjectSchemaStmt(from);
3369 case T_AlterOwnerStmt:
3370 retval = _copyAlterOwnerStmt(from);
3373 retval = _copyRuleStmt(from);
3376 retval = _copyNotifyStmt(from);
3379 retval = _copyListenStmt(from);
3381 case T_UnlistenStmt:
3382 retval = _copyUnlistenStmt(from);
3384 case T_TransactionStmt:
3385 retval = _copyTransactionStmt(from);
3387 case T_CompositeTypeStmt:
3388 retval = _copyCompositeTypeStmt(from);
3390 case T_CreateEnumStmt:
3391 retval = _copyCreateEnumStmt(from);
3394 retval = _copyViewStmt(from);
3397 retval = _copyLoadStmt(from);
3399 case T_CreateDomainStmt:
3400 retval = _copyCreateDomainStmt(from);
3402 case T_CreateOpClassStmt:
3403 retval = _copyCreateOpClassStmt(from);
3405 case T_CreateOpClassItem:
3406 retval = _copyCreateOpClassItem(from);
3408 case T_CreateOpFamilyStmt:
3409 retval = _copyCreateOpFamilyStmt(from);
3411 case T_AlterOpFamilyStmt:
3412 retval = _copyAlterOpFamilyStmt(from);
3414 case T_CreatedbStmt:
3415 retval = _copyCreatedbStmt(from);
3417 case T_AlterDatabaseStmt:
3418 retval = _copyAlterDatabaseStmt(from);
3420 case T_AlterDatabaseSetStmt:
3421 retval = _copyAlterDatabaseSetStmt(from);
3424 retval = _copyDropdbStmt(from);
3427 retval = _copyVacuumStmt(from);
3430 retval = _copyExplainStmt(from);
3432 case T_CreateSeqStmt:
3433 retval = _copyCreateSeqStmt(from);
3435 case T_AlterSeqStmt:
3436 retval = _copyAlterSeqStmt(from);
3438 case T_VariableSetStmt:
3439 retval = _copyVariableSetStmt(from);
3441 case T_VariableShowStmt:
3442 retval = _copyVariableShowStmt(from);
3445 retval = _copyDiscardStmt(from);
3447 case T_CreateTableSpaceStmt:
3448 retval = _copyCreateTableSpaceStmt(from);
3450 case T_DropTableSpaceStmt:
3451 retval = _copyDropTableSpaceStmt(from);
3453 case T_CreateTrigStmt:
3454 retval = _copyCreateTrigStmt(from);
3456 case T_DropPropertyStmt:
3457 retval = _copyDropPropertyStmt(from);
3459 case T_CreatePLangStmt:
3460 retval = _copyCreatePLangStmt(from);
3462 case T_DropPLangStmt:
3463 retval = _copyDropPLangStmt(from);
3465 case T_CreateRoleStmt:
3466 retval = _copyCreateRoleStmt(from);
3468 case T_AlterRoleStmt:
3469 retval = _copyAlterRoleStmt(from);
3471 case T_AlterRoleSetStmt:
3472 retval = _copyAlterRoleSetStmt(from);
3474 case T_DropRoleStmt:
3475 retval = _copyDropRoleStmt(from);
3478 retval = _copyLockStmt(from);
3480 case T_ConstraintsSetStmt:
3481 retval = _copyConstraintsSetStmt(from);
3484 retval = _copyReindexStmt(from);
3486 case T_CheckPointStmt:
3487 retval = (void *) makeNode(CheckPointStmt);
3489 case T_CreateSchemaStmt:
3490 retval = _copyCreateSchemaStmt(from);
3492 case T_CreateConversionStmt:
3493 retval = _copyCreateConversionStmt(from);
3495 case T_CreateCastStmt:
3496 retval = _copyCreateCastStmt(from);
3498 case T_DropCastStmt:
3499 retval = _copyDropCastStmt(from);
3502 retval = _copyPrepareStmt(from);
3505 retval = _copyExecuteStmt(from);
3507 case T_DeallocateStmt:
3508 retval = _copyDeallocateStmt(from);
3510 case T_DropOwnedStmt:
3511 retval = _copyDropOwnedStmt(from);
3513 case T_ReassignOwnedStmt:
3514 retval = _copyReassignOwnedStmt(from);
3516 case T_AlterTSDictionaryStmt:
3517 retval = _copyAlterTSDictionaryStmt(from);
3519 case T_AlterTSConfigurationStmt:
3520 retval = _copyAlterTSConfigurationStmt(from);
3524 retval = _copyAExpr(from);
3527 retval = _copyColumnRef(from);
3530 retval = _copyParamRef(from);
3533 retval = _copyAConst(from);
3536 retval = _copyFuncCall(from);
3539 retval = _copyAIndices(from);
3541 case T_A_Indirection:
3542 retval = _copyA_Indirection(from);
3545 retval = _copyA_ArrayExpr(from);
3548 retval = _copyResTarget(from);
3551 retval = _copyTypeCast(from);
3554 retval = _copySortBy(from);
3556 case T_RangeSubselect:
3557 retval = _copyRangeSubselect(from);
3559 case T_RangeFunction:
3560 retval = _copyRangeFunction(from);
3563 retval = _copyTypeName(from);
3566 retval = _copyIndexElem(from);
3569 retval = _copyColumnDef(from);
3572 retval = _copyConstraint(from);
3575 retval = _copyDefElem(from);
3577 case T_LockingClause:
3578 retval = _copyLockingClause(from);
3580 case T_RangeTblEntry:
3581 retval = _copyRangeTblEntry(from);
3583 case T_SortGroupClause:
3584 retval = _copySortGroupClause(from);
3586 case T_RowMarkClause:
3587 retval = _copyRowMarkClause(from);
3589 case T_FkConstraint:
3590 retval = _copyFkConstraint(from);
3593 retval = _copyPrivGrantee(from);
3595 case T_FuncWithArgs:
3596 retval = _copyFuncWithArgs(from);
3598 case T_XmlSerialize:
3599 retval = _copyXmlSerialize(from);
3603 elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3604 retval = from; /* keep compiler quiet */