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-2002, PostgreSQL Global Development Group
15 * Portions Copyright (c) 1994, Regents of the University of California
18 * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.233 2002/12/14 00:17:50 tgl Exp $
20 *-------------------------------------------------------------------------
25 #include "nodes/parsenodes.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
32 * Macros to simplify copying of different kinds of fields. Use these
33 * wherever possible to reduce the chance for silly typos. Note that these
34 * hard-wire the convention that the local variables in a Copy routine are
35 * named 'newnode' and 'from'.
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40 (newnode->fldname = from->fldname)
42 /* Copy a field that is a pointer to some kind of Node or Node tree */
43 #define COPY_NODE_FIELD(fldname) \
44 (newnode->fldname = copyObject(from->fldname))
46 /* Copy a field that is a pointer to a list of integers */
47 #define COPY_INTLIST_FIELD(fldname) \
48 (newnode->fldname = listCopy(from->fldname))
50 /* Copy a field that is a pointer to a C string, or perhaps NULL */
51 #define COPY_STRING_FIELD(fldname) \
52 (newnode->fldname = from->fldname ? pstrdup(from->fldname) : (char *) NULL)
54 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
55 #define COPY_POINTER_FIELD(fldname, sz) \
58 newnode->fldname = palloc(_size); \
59 memcpy(newnode->fldname, from->fldname, _size); \
65 * This copy function only copies the "cons-cells" of the list, not the
66 * pointed-to objects. (Use copyObject if you want a "deep" copy.)
68 * We also use this function for copying lists of integers, which is
69 * grotty but unlikely to break --- it could fail if sizeof(pointer)
70 * is less than sizeof(int), but I don't know any such machines...
72 * Note that copyObject will surely coredump if applied to a list
82 /* rather ugly coding for speed... */
86 newlist = nl = makeList1(lfirst(list));
88 foreach(l, lnext(list))
90 lnext(nl) = makeList1(lfirst(l));
96 /* ****************************************************************
97 * plannodes.h copy functions
98 * ****************************************************************
104 * This function copies the fields of the Plan node. It is used by
105 * all the copy functions for classes which inherit from Plan.
108 CopyPlanFields(Plan *from, Plan *newnode)
110 COPY_SCALAR_FIELD(startup_cost);
111 COPY_SCALAR_FIELD(total_cost);
112 COPY_SCALAR_FIELD(plan_rows);
113 COPY_SCALAR_FIELD(plan_width);
114 COPY_NODE_FIELD(targetlist);
115 COPY_NODE_FIELD(qual);
116 COPY_NODE_FIELD(lefttree);
117 COPY_NODE_FIELD(righttree);
118 COPY_NODE_FIELD(initPlan);
119 COPY_INTLIST_FIELD(extParam);
120 COPY_INTLIST_FIELD(locParam);
121 COPY_SCALAR_FIELD(nParamExec);
128 _copyPlan(Plan *from)
130 Plan *newnode = makeNode(Plan);
133 * copy node superclass fields
135 CopyPlanFields(from, newnode);
145 _copyResult(Result *from)
147 Result *newnode = makeNode(Result);
150 * copy node superclass fields
152 CopyPlanFields((Plan *) from, (Plan *) newnode);
155 * copy remainder of node
157 COPY_NODE_FIELD(resconstantqual);
166 _copyAppend(Append *from)
168 Append *newnode = makeNode(Append);
171 * copy node superclass fields
173 CopyPlanFields((Plan *) from, (Plan *) newnode);
176 * copy remainder of node
178 COPY_NODE_FIELD(appendplans);
179 COPY_SCALAR_FIELD(isTarget);
188 * This function copies the fields of the Scan node. It is used by
189 * all the copy functions for classes which inherit from Scan.
192 CopyScanFields(Scan *from, Scan *newnode)
194 CopyPlanFields((Plan *) from, (Plan *) newnode);
196 COPY_SCALAR_FIELD(scanrelid);
203 _copyScan(Scan *from)
205 Scan *newnode = makeNode(Scan);
208 * copy node superclass fields
210 CopyScanFields((Scan *) from, (Scan *) newnode);
219 _copySeqScan(SeqScan *from)
221 SeqScan *newnode = makeNode(SeqScan);
224 * copy node superclass fields
226 CopyScanFields((Scan *) from, (Scan *) newnode);
235 _copyIndexScan(IndexScan *from)
237 IndexScan *newnode = makeNode(IndexScan);
240 * copy node superclass fields
242 CopyScanFields((Scan *) from, (Scan *) newnode);
245 * copy remainder of node
247 COPY_INTLIST_FIELD(indxid);
248 COPY_NODE_FIELD(indxqual);
249 COPY_NODE_FIELD(indxqualorig);
250 COPY_SCALAR_FIELD(indxorderdir);
259 _copyTidScan(TidScan *from)
261 TidScan *newnode = makeNode(TidScan);
264 * copy node superclass fields
266 CopyScanFields((Scan *) from, (Scan *) newnode);
269 * copy remainder of node
271 COPY_NODE_FIELD(tideval);
279 static SubqueryScan *
280 _copySubqueryScan(SubqueryScan *from)
282 SubqueryScan *newnode = makeNode(SubqueryScan);
285 * copy node superclass fields
287 CopyScanFields((Scan *) from, (Scan *) newnode);
290 * copy remainder of node
292 COPY_NODE_FIELD(subplan);
300 static FunctionScan *
301 _copyFunctionScan(FunctionScan *from)
303 FunctionScan *newnode = makeNode(FunctionScan);
306 * copy node superclass fields
308 CopyScanFields((Scan *) from, (Scan *) newnode);
316 * This function copies the fields of the Join node. It is used by
317 * all the copy functions for classes which inherit from Join.
320 CopyJoinFields(Join *from, Join *newnode)
322 CopyPlanFields((Plan *) from, (Plan *) newnode);
324 COPY_SCALAR_FIELD(jointype);
325 COPY_NODE_FIELD(joinqual);
333 _copyJoin(Join *from)
335 Join *newnode = makeNode(Join);
338 * copy node superclass fields
340 CopyJoinFields(from, newnode);
350 _copyNestLoop(NestLoop *from)
352 NestLoop *newnode = makeNode(NestLoop);
355 * copy node superclass fields
357 CopyJoinFields((Join *) from, (Join *) newnode);
367 _copyMergeJoin(MergeJoin *from)
369 MergeJoin *newnode = makeNode(MergeJoin);
372 * copy node superclass fields
374 CopyJoinFields((Join *) from, (Join *) newnode);
377 * copy remainder of node
379 COPY_NODE_FIELD(mergeclauses);
388 _copyHashJoin(HashJoin *from)
390 HashJoin *newnode = makeNode(HashJoin);
393 * copy node superclass fields
395 CopyJoinFields((Join *) from, (Join *) newnode);
398 * copy remainder of node
400 COPY_NODE_FIELD(hashclauses);
410 _copyMaterial(Material *from)
412 Material *newnode = makeNode(Material);
415 * copy node superclass fields
417 CopyPlanFields((Plan *) from, (Plan *) newnode);
427 _copySort(Sort *from)
429 Sort *newnode = makeNode(Sort);
432 * copy node superclass fields
434 CopyPlanFields((Plan *) from, (Plan *) newnode);
436 COPY_SCALAR_FIELD(keycount);
446 _copyGroup(Group *from)
448 Group *newnode = makeNode(Group);
450 CopyPlanFields((Plan *) from, (Plan *) newnode);
452 COPY_SCALAR_FIELD(numCols);
453 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
464 Agg *newnode = makeNode(Agg);
466 CopyPlanFields((Plan *) from, (Plan *) newnode);
468 COPY_SCALAR_FIELD(aggstrategy);
469 COPY_SCALAR_FIELD(numCols);
470 if (from->numCols > 0)
471 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
472 COPY_SCALAR_FIELD(numGroups);
481 _copyUnique(Unique *from)
483 Unique *newnode = makeNode(Unique);
486 * copy node superclass fields
488 CopyPlanFields((Plan *) from, (Plan *) newnode);
491 * copy remainder of node
493 COPY_SCALAR_FIELD(numCols);
494 COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
503 _copyHash(Hash *from)
505 Hash *newnode = makeNode(Hash);
508 * copy node superclass fields
510 CopyPlanFields((Plan *) from, (Plan *) newnode);
513 * copy remainder of node
515 COPY_NODE_FIELD(hashkeys);
524 _copySetOp(SetOp *from)
526 SetOp *newnode = makeNode(SetOp);
529 * copy node superclass fields
531 CopyPlanFields((Plan *) from, (Plan *) newnode);
534 * copy remainder of node
536 COPY_SCALAR_FIELD(cmd);
537 COPY_SCALAR_FIELD(numCols);
538 COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
539 COPY_SCALAR_FIELD(flagColIdx);
548 _copyLimit(Limit *from)
550 Limit *newnode = makeNode(Limit);
553 * copy node superclass fields
555 CopyPlanFields((Plan *) from, (Plan *) newnode);
558 * copy remainder of node
560 COPY_NODE_FIELD(limitOffset);
561 COPY_NODE_FIELD(limitCount);
566 /* ****************************************************************
567 * primnodes.h copy functions
568 * ****************************************************************
575 _copyResdom(Resdom *from)
577 Resdom *newnode = makeNode(Resdom);
579 COPY_SCALAR_FIELD(resno);
580 COPY_SCALAR_FIELD(restype);
581 COPY_SCALAR_FIELD(restypmod);
582 COPY_STRING_FIELD(resname);
583 COPY_SCALAR_FIELD(ressortgroupref);
584 COPY_SCALAR_FIELD(reskey);
585 COPY_SCALAR_FIELD(reskeyop);
586 COPY_SCALAR_FIELD(resjunk);
595 _copyAlias(Alias *from)
597 Alias *newnode = makeNode(Alias);
599 COPY_STRING_FIELD(aliasname);
600 COPY_NODE_FIELD(colnames);
609 _copyRangeVar(RangeVar *from)
611 RangeVar *newnode = makeNode(RangeVar);
613 COPY_STRING_FIELD(catalogname);
614 COPY_STRING_FIELD(schemaname);
615 COPY_STRING_FIELD(relname);
616 COPY_SCALAR_FIELD(inhOpt);
617 COPY_SCALAR_FIELD(istemp);
618 COPY_NODE_FIELD(alias);
624 * We don't need a _copyExpr because Expr is an abstract supertype which
625 * should never actually get instantiated. Also, since it has no common
626 * fields except NodeTag, there's no need for a helper routine to factor
627 * out copying the common fields...
636 Var *newnode = makeNode(Var);
638 COPY_SCALAR_FIELD(varno);
639 COPY_SCALAR_FIELD(varattno);
640 COPY_SCALAR_FIELD(vartype);
641 COPY_SCALAR_FIELD(vartypmod);
642 COPY_SCALAR_FIELD(varlevelsup);
643 COPY_SCALAR_FIELD(varnoold);
644 COPY_SCALAR_FIELD(varoattno);
653 _copyConst(Const *from)
655 Const *newnode = makeNode(Const);
657 COPY_SCALAR_FIELD(consttype);
658 COPY_SCALAR_FIELD(constlen);
660 if (from->constbyval || from->constisnull)
663 * passed by value so just copy the datum. Also, don't try to copy
664 * struct when value is null!
666 newnode->constvalue = from->constvalue;
671 * passed by reference. We need a palloc'd copy.
673 newnode->constvalue = datumCopy(from->constvalue,
678 COPY_SCALAR_FIELD(constisnull);
679 COPY_SCALAR_FIELD(constbyval);
688 _copyParam(Param *from)
690 Param *newnode = makeNode(Param);
692 COPY_SCALAR_FIELD(paramkind);
693 COPY_SCALAR_FIELD(paramid);
694 COPY_STRING_FIELD(paramname);
695 COPY_SCALAR_FIELD(paramtype);
704 _copyAggref(Aggref *from)
706 Aggref *newnode = makeNode(Aggref);
708 COPY_SCALAR_FIELD(aggfnoid);
709 COPY_SCALAR_FIELD(aggtype);
710 COPY_NODE_FIELD(target);
711 COPY_SCALAR_FIELD(aggstar);
712 COPY_SCALAR_FIELD(aggdistinct);
721 _copyArrayRef(ArrayRef *from)
723 ArrayRef *newnode = makeNode(ArrayRef);
725 COPY_SCALAR_FIELD(refrestype);
726 COPY_SCALAR_FIELD(refattrlength);
727 COPY_SCALAR_FIELD(refelemlength);
728 COPY_SCALAR_FIELD(refelembyval);
729 COPY_SCALAR_FIELD(refelemalign);
730 COPY_NODE_FIELD(refupperindexpr);
731 COPY_NODE_FIELD(reflowerindexpr);
732 COPY_NODE_FIELD(refexpr);
733 COPY_NODE_FIELD(refassgnexpr);
742 _copyFuncExpr(FuncExpr *from)
744 FuncExpr *newnode = makeNode(FuncExpr);
746 COPY_SCALAR_FIELD(funcid);
747 COPY_SCALAR_FIELD(funcresulttype);
748 COPY_SCALAR_FIELD(funcretset);
749 COPY_SCALAR_FIELD(funcformat);
750 COPY_NODE_FIELD(args);
759 _copyOpExpr(OpExpr *from)
761 OpExpr *newnode = makeNode(OpExpr);
763 COPY_SCALAR_FIELD(opno);
764 COPY_SCALAR_FIELD(opfuncid);
765 COPY_SCALAR_FIELD(opresulttype);
766 COPY_SCALAR_FIELD(opretset);
767 COPY_NODE_FIELD(args);
775 static DistinctExpr *
776 _copyDistinctExpr(DistinctExpr *from)
778 DistinctExpr *newnode = makeNode(DistinctExpr);
780 COPY_SCALAR_FIELD(opno);
781 COPY_SCALAR_FIELD(opfuncid);
782 COPY_SCALAR_FIELD(opresulttype);
783 COPY_SCALAR_FIELD(opretset);
784 COPY_NODE_FIELD(args);
793 _copyBoolExpr(BoolExpr *from)
795 BoolExpr *newnode = makeNode(BoolExpr);
797 COPY_SCALAR_FIELD(boolop);
798 COPY_NODE_FIELD(args);
807 _copySubLink(SubLink *from)
809 SubLink *newnode = makeNode(SubLink);
811 COPY_SCALAR_FIELD(subLinkType);
812 COPY_SCALAR_FIELD(useor);
813 COPY_NODE_FIELD(lefthand);
814 COPY_NODE_FIELD(oper);
815 COPY_NODE_FIELD(subselect);
824 _copySubPlan(SubPlan *from)
826 SubPlan *newnode = makeNode(SubPlan);
828 COPY_SCALAR_FIELD(subLinkType);
829 COPY_SCALAR_FIELD(useor);
830 COPY_NODE_FIELD(oper);
831 COPY_NODE_FIELD(plan);
832 COPY_SCALAR_FIELD(plan_id);
833 COPY_NODE_FIELD(rtable);
834 COPY_INTLIST_FIELD(setParam);
835 COPY_INTLIST_FIELD(parParam);
836 COPY_NODE_FIELD(args);
845 _copyFieldSelect(FieldSelect *from)
847 FieldSelect *newnode = makeNode(FieldSelect);
849 COPY_NODE_FIELD(arg);
850 COPY_SCALAR_FIELD(fieldnum);
851 COPY_SCALAR_FIELD(resulttype);
852 COPY_SCALAR_FIELD(resulttypmod);
861 _copyRelabelType(RelabelType *from)
863 RelabelType *newnode = makeNode(RelabelType);
865 COPY_NODE_FIELD(arg);
866 COPY_SCALAR_FIELD(resulttype);
867 COPY_SCALAR_FIELD(resulttypmod);
868 COPY_SCALAR_FIELD(relabelformat);
877 _copyCaseExpr(CaseExpr *from)
879 CaseExpr *newnode = makeNode(CaseExpr);
881 COPY_SCALAR_FIELD(casetype);
882 COPY_NODE_FIELD(arg);
883 COPY_NODE_FIELD(args);
884 COPY_NODE_FIELD(defresult);
893 _copyCaseWhen(CaseWhen *from)
895 CaseWhen *newnode = makeNode(CaseWhen);
897 COPY_NODE_FIELD(expr);
898 COPY_NODE_FIELD(result);
907 _copyNullTest(NullTest *from)
909 NullTest *newnode = makeNode(NullTest);
911 COPY_NODE_FIELD(arg);
912 COPY_SCALAR_FIELD(nulltesttype);
921 _copyBooleanTest(BooleanTest *from)
923 BooleanTest *newnode = makeNode(BooleanTest);
925 COPY_NODE_FIELD(arg);
926 COPY_SCALAR_FIELD(booltesttype);
932 * _copyConstraintTest
934 static ConstraintTest *
935 _copyConstraintTest(ConstraintTest *from)
937 ConstraintTest *newnode = makeNode(ConstraintTest);
939 COPY_NODE_FIELD(arg);
940 COPY_SCALAR_FIELD(testtype);
941 COPY_STRING_FIELD(name);
942 COPY_STRING_FIELD(domname);
943 COPY_NODE_FIELD(check_expr);
949 * _copyConstraintTestValue
951 static ConstraintTestValue *
952 _copyConstraintTestValue(ConstraintTestValue *from)
954 ConstraintTestValue *newnode = makeNode(ConstraintTestValue);
956 COPY_SCALAR_FIELD(typeId);
957 COPY_SCALAR_FIELD(typeMod);
966 _copyTargetEntry(TargetEntry *from)
968 TargetEntry *newnode = makeNode(TargetEntry);
970 COPY_NODE_FIELD(resdom);
971 COPY_NODE_FIELD(expr);
980 _copyRangeTblRef(RangeTblRef *from)
982 RangeTblRef *newnode = makeNode(RangeTblRef);
984 COPY_SCALAR_FIELD(rtindex);
993 _copyJoinExpr(JoinExpr *from)
995 JoinExpr *newnode = makeNode(JoinExpr);
997 COPY_SCALAR_FIELD(jointype);
998 COPY_SCALAR_FIELD(isNatural);
999 COPY_NODE_FIELD(larg);
1000 COPY_NODE_FIELD(rarg);
1001 COPY_NODE_FIELD(using);
1002 COPY_NODE_FIELD(quals);
1003 COPY_NODE_FIELD(alias);
1004 COPY_SCALAR_FIELD(rtindex);
1013 _copyFromExpr(FromExpr *from)
1015 FromExpr *newnode = makeNode(FromExpr);
1017 COPY_NODE_FIELD(fromlist);
1018 COPY_NODE_FIELD(quals);
1023 /* ****************************************************************
1024 * relation.h copy functions
1026 * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1027 * There are some subsidiary structs that are useful to copy, though.
1028 * ****************************************************************
1034 static PathKeyItem *
1035 _copyPathKeyItem(PathKeyItem *from)
1037 PathKeyItem *newnode = makeNode(PathKeyItem);
1039 COPY_NODE_FIELD(key);
1040 COPY_SCALAR_FIELD(sortop);
1048 static RestrictInfo *
1049 _copyRestrictInfo(RestrictInfo *from)
1051 RestrictInfo *newnode = makeNode(RestrictInfo);
1053 COPY_NODE_FIELD(clause);
1054 COPY_SCALAR_FIELD(ispusheddown);
1055 COPY_NODE_FIELD(subclauseindices); /* XXX probably bad */
1056 COPY_SCALAR_FIELD(eval_cost);
1057 COPY_SCALAR_FIELD(this_selec);
1058 COPY_SCALAR_FIELD(mergejoinoperator);
1059 COPY_SCALAR_FIELD(left_sortop);
1060 COPY_SCALAR_FIELD(right_sortop);
1063 * Do not copy pathkeys, since they'd not be canonical in a copied
1066 newnode->left_pathkey = NIL;
1067 newnode->right_pathkey = NIL;
1069 COPY_SCALAR_FIELD(left_mergescansel);
1070 COPY_SCALAR_FIELD(right_mergescansel);
1071 COPY_SCALAR_FIELD(hashjoinoperator);
1072 COPY_SCALAR_FIELD(left_bucketsize);
1073 COPY_SCALAR_FIELD(right_bucketsize);
1082 _copyJoinInfo(JoinInfo *from)
1084 JoinInfo *newnode = makeNode(JoinInfo);
1086 COPY_INTLIST_FIELD(unjoined_relids);
1087 COPY_NODE_FIELD(jinfo_restrictinfo);
1092 /* ****************************************************************
1093 * parsenodes.h copy functions
1094 * ****************************************************************
1097 static RangeTblEntry *
1098 _copyRangeTblEntry(RangeTblEntry *from)
1100 RangeTblEntry *newnode = makeNode(RangeTblEntry);
1102 COPY_SCALAR_FIELD(rtekind);
1103 COPY_SCALAR_FIELD(relid);
1104 COPY_NODE_FIELD(subquery);
1105 COPY_NODE_FIELD(funcexpr);
1106 COPY_NODE_FIELD(coldeflist);
1107 COPY_SCALAR_FIELD(jointype);
1108 COPY_NODE_FIELD(joinaliasvars);
1109 COPY_NODE_FIELD(alias);
1110 COPY_NODE_FIELD(eref);
1111 COPY_SCALAR_FIELD(inh);
1112 COPY_SCALAR_FIELD(inFromCl);
1113 COPY_SCALAR_FIELD(checkForRead);
1114 COPY_SCALAR_FIELD(checkForWrite);
1115 COPY_SCALAR_FIELD(checkAsUser);
1120 static FkConstraint *
1121 _copyFkConstraint(FkConstraint *from)
1123 FkConstraint *newnode = makeNode(FkConstraint);
1125 COPY_STRING_FIELD(constr_name);
1126 COPY_NODE_FIELD(pktable);
1127 COPY_NODE_FIELD(fk_attrs);
1128 COPY_NODE_FIELD(pk_attrs);
1129 COPY_SCALAR_FIELD(fk_matchtype);
1130 COPY_SCALAR_FIELD(fk_upd_action);
1131 COPY_SCALAR_FIELD(fk_del_action);
1132 COPY_SCALAR_FIELD(deferrable);
1133 COPY_SCALAR_FIELD(initdeferred);
1134 COPY_SCALAR_FIELD(skip_validation);
1140 _copySortClause(SortClause *from)
1142 SortClause *newnode = makeNode(SortClause);
1144 COPY_SCALAR_FIELD(tleSortGroupRef);
1145 COPY_SCALAR_FIELD(sortop);
1150 static GroupClause *
1151 _copyGroupClause(GroupClause *from)
1153 GroupClause *newnode = makeNode(GroupClause);
1155 COPY_SCALAR_FIELD(tleSortGroupRef);
1156 COPY_SCALAR_FIELD(sortop);
1162 _copyAExpr(A_Expr *from)
1164 A_Expr *newnode = makeNode(A_Expr);
1166 COPY_SCALAR_FIELD(oper);
1167 COPY_NODE_FIELD(name);
1168 COPY_NODE_FIELD(lexpr);
1169 COPY_NODE_FIELD(rexpr);
1175 _copyColumnRef(ColumnRef *from)
1177 ColumnRef *newnode = makeNode(ColumnRef);
1179 COPY_NODE_FIELD(fields);
1180 COPY_NODE_FIELD(indirection);
1186 _copyParamRef(ParamRef *from)
1188 ParamRef *newnode = makeNode(ParamRef);
1190 COPY_SCALAR_FIELD(number);
1191 COPY_NODE_FIELD(fields);
1192 COPY_NODE_FIELD(indirection);
1198 _copyAConst(A_Const *from)
1200 A_Const *newnode = makeNode(A_Const);
1202 /* This part must duplicate _copyValue */
1203 COPY_SCALAR_FIELD(val.type);
1204 switch (from->val.type)
1207 COPY_SCALAR_FIELD(val.val.ival);
1212 COPY_STRING_FIELD(val.val.str);
1218 elog(ERROR, "_copyAConst: unknown node type %d", from->val.type);
1222 COPY_NODE_FIELD(typename);
1228 _copyFuncCall(FuncCall *from)
1230 FuncCall *newnode = makeNode(FuncCall);
1232 COPY_NODE_FIELD(funcname);
1233 COPY_NODE_FIELD(args);
1234 COPY_SCALAR_FIELD(agg_star);
1235 COPY_SCALAR_FIELD(agg_distinct);
1241 _copyAIndices(A_Indices *from)
1243 A_Indices *newnode = makeNode(A_Indices);
1245 COPY_NODE_FIELD(lidx);
1246 COPY_NODE_FIELD(uidx);
1251 static ExprFieldSelect *
1252 _copyExprFieldSelect(ExprFieldSelect *from)
1254 ExprFieldSelect *newnode = makeNode(ExprFieldSelect);
1256 COPY_NODE_FIELD(arg);
1257 COPY_NODE_FIELD(fields);
1258 COPY_NODE_FIELD(indirection);
1264 _copyResTarget(ResTarget *from)
1266 ResTarget *newnode = makeNode(ResTarget);
1268 COPY_STRING_FIELD(name);
1269 COPY_NODE_FIELD(indirection);
1270 COPY_NODE_FIELD(val);
1276 _copyTypeName(TypeName *from)
1278 TypeName *newnode = makeNode(TypeName);
1280 COPY_NODE_FIELD(names);
1281 COPY_SCALAR_FIELD(typeid);
1282 COPY_SCALAR_FIELD(timezone);
1283 COPY_SCALAR_FIELD(setof);
1284 COPY_SCALAR_FIELD(pct_type);
1285 COPY_SCALAR_FIELD(typmod);
1286 COPY_NODE_FIELD(arrayBounds);
1291 static SortGroupBy *
1292 _copySortGroupBy(SortGroupBy *from)
1294 SortGroupBy *newnode = makeNode(SortGroupBy);
1296 COPY_NODE_FIELD(useOp);
1297 COPY_NODE_FIELD(node);
1302 static RangeSubselect *
1303 _copyRangeSubselect(RangeSubselect *from)
1305 RangeSubselect *newnode = makeNode(RangeSubselect);
1307 COPY_NODE_FIELD(subquery);
1308 COPY_NODE_FIELD(alias);
1313 static RangeFunction *
1314 _copyRangeFunction(RangeFunction *from)
1316 RangeFunction *newnode = makeNode(RangeFunction);
1318 COPY_NODE_FIELD(funccallnode);
1319 COPY_NODE_FIELD(alias);
1320 COPY_NODE_FIELD(coldeflist);
1326 _copyTypeCast(TypeCast *from)
1328 TypeCast *newnode = makeNode(TypeCast);
1330 COPY_NODE_FIELD(arg);
1331 COPY_NODE_FIELD(typename);
1337 _copyIndexElem(IndexElem *from)
1339 IndexElem *newnode = makeNode(IndexElem);
1341 COPY_STRING_FIELD(name);
1342 COPY_NODE_FIELD(funcname);
1343 COPY_NODE_FIELD(args);
1344 COPY_NODE_FIELD(opclass);
1350 _copyColumnDef(ColumnDef *from)
1352 ColumnDef *newnode = makeNode(ColumnDef);
1354 COPY_STRING_FIELD(colname);
1355 COPY_NODE_FIELD(typename);
1356 COPY_SCALAR_FIELD(inhcount);
1357 COPY_SCALAR_FIELD(is_local);
1358 COPY_SCALAR_FIELD(is_not_null);
1359 COPY_NODE_FIELD(raw_default);
1360 COPY_STRING_FIELD(cooked_default);
1361 COPY_NODE_FIELD(constraints);
1362 COPY_NODE_FIELD(support);
1368 _copyConstraint(Constraint *from)
1370 Constraint *newnode = makeNode(Constraint);
1372 COPY_SCALAR_FIELD(contype);
1373 COPY_STRING_FIELD(name);
1374 COPY_NODE_FIELD(raw_expr);
1375 COPY_STRING_FIELD(cooked_expr);
1376 COPY_NODE_FIELD(keys);
1382 _copyDefElem(DefElem *from)
1384 DefElem *newnode = makeNode(DefElem);
1386 COPY_STRING_FIELD(defname);
1387 COPY_NODE_FIELD(arg);
1393 _copyQuery(Query *from)
1395 Query *newnode = makeNode(Query);
1397 COPY_SCALAR_FIELD(commandType);
1398 COPY_SCALAR_FIELD(querySource);
1399 COPY_NODE_FIELD(utilityStmt);
1400 COPY_SCALAR_FIELD(resultRelation);
1401 COPY_NODE_FIELD(into);
1402 COPY_SCALAR_FIELD(isPortal);
1403 COPY_SCALAR_FIELD(isBinary);
1404 COPY_SCALAR_FIELD(hasAggs);
1405 COPY_SCALAR_FIELD(hasSubLinks);
1406 COPY_NODE_FIELD(rtable);
1407 COPY_NODE_FIELD(jointree);
1408 COPY_INTLIST_FIELD(rowMarks);
1409 COPY_NODE_FIELD(targetList);
1410 COPY_NODE_FIELD(groupClause);
1411 COPY_NODE_FIELD(havingQual);
1412 COPY_NODE_FIELD(distinctClause);
1413 COPY_NODE_FIELD(sortClause);
1414 COPY_NODE_FIELD(limitOffset);
1415 COPY_NODE_FIELD(limitCount);
1416 COPY_NODE_FIELD(setOperations);
1417 COPY_INTLIST_FIELD(resultRelations);
1420 * We do not copy the planner internal fields: base_rel_list,
1421 * other_rel_list, join_rel_list, equi_key_list, query_pathkeys,
1422 * hasJoinRTEs. That would get us into copying RelOptInfo/Path
1423 * trees, which we don't want to do.
1430 _copyInsertStmt(InsertStmt *from)
1432 InsertStmt *newnode = makeNode(InsertStmt);
1434 COPY_NODE_FIELD(relation);
1435 COPY_NODE_FIELD(cols);
1436 COPY_NODE_FIELD(targetList);
1437 COPY_NODE_FIELD(selectStmt);
1443 _copyDeleteStmt(DeleteStmt *from)
1445 DeleteStmt *newnode = makeNode(DeleteStmt);
1447 COPY_NODE_FIELD(relation);
1448 COPY_NODE_FIELD(whereClause);
1454 _copyUpdateStmt(UpdateStmt *from)
1456 UpdateStmt *newnode = makeNode(UpdateStmt);
1458 COPY_NODE_FIELD(relation);
1459 COPY_NODE_FIELD(targetList);
1460 COPY_NODE_FIELD(whereClause);
1461 COPY_NODE_FIELD(fromClause);
1467 _copySelectStmt(SelectStmt *from)
1469 SelectStmt *newnode = makeNode(SelectStmt);
1471 COPY_NODE_FIELD(distinctClause);
1472 COPY_NODE_FIELD(into);
1473 COPY_NODE_FIELD(intoColNames);
1474 COPY_NODE_FIELD(targetList);
1475 COPY_NODE_FIELD(fromClause);
1476 COPY_NODE_FIELD(whereClause);
1477 COPY_NODE_FIELD(groupClause);
1478 COPY_NODE_FIELD(havingClause);
1479 COPY_NODE_FIELD(sortClause);
1480 COPY_STRING_FIELD(portalname);
1481 COPY_SCALAR_FIELD(binary);
1482 COPY_NODE_FIELD(limitOffset);
1483 COPY_NODE_FIELD(limitCount);
1484 COPY_NODE_FIELD(forUpdate);
1485 COPY_SCALAR_FIELD(op);
1486 COPY_SCALAR_FIELD(all);
1487 COPY_NODE_FIELD(larg);
1488 COPY_NODE_FIELD(rarg);
1493 static SetOperationStmt *
1494 _copySetOperationStmt(SetOperationStmt *from)
1496 SetOperationStmt *newnode = makeNode(SetOperationStmt);
1498 COPY_SCALAR_FIELD(op);
1499 COPY_SCALAR_FIELD(all);
1500 COPY_NODE_FIELD(larg);
1501 COPY_NODE_FIELD(rarg);
1502 COPY_INTLIST_FIELD(colTypes);
1507 static AlterTableStmt *
1508 _copyAlterTableStmt(AlterTableStmt *from)
1510 AlterTableStmt *newnode = makeNode(AlterTableStmt);
1512 COPY_SCALAR_FIELD(subtype);
1513 COPY_NODE_FIELD(relation);
1514 COPY_STRING_FIELD(name);
1515 COPY_NODE_FIELD(def);
1516 COPY_SCALAR_FIELD(behavior);
1521 static AlterDomainStmt *
1522 _copyAlterDomainStmt(AlterDomainStmt *from)
1524 AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1526 COPY_SCALAR_FIELD(subtype);
1527 COPY_NODE_FIELD(typename);
1528 COPY_STRING_FIELD(name);
1529 COPY_NODE_FIELD(def);
1530 COPY_SCALAR_FIELD(behavior);
1536 _copyGrantStmt(GrantStmt *from)
1538 GrantStmt *newnode = makeNode(GrantStmt);
1540 COPY_SCALAR_FIELD(is_grant);
1541 COPY_SCALAR_FIELD(objtype);
1542 COPY_NODE_FIELD(objects);
1543 COPY_INTLIST_FIELD(privileges);
1544 COPY_NODE_FIELD(grantees);
1549 static PrivGrantee *
1550 _copyPrivGrantee(PrivGrantee *from)
1552 PrivGrantee *newnode = makeNode(PrivGrantee);
1554 COPY_STRING_FIELD(username);
1555 COPY_STRING_FIELD(groupname);
1560 static FuncWithArgs *
1561 _copyFuncWithArgs(FuncWithArgs *from)
1563 FuncWithArgs *newnode = makeNode(FuncWithArgs);
1565 COPY_NODE_FIELD(funcname);
1566 COPY_NODE_FIELD(funcargs);
1571 static InsertDefault *
1572 _copyInsertDefault(InsertDefault *from)
1574 InsertDefault *newnode = makeNode(InsertDefault);
1580 static ClosePortalStmt *
1581 _copyClosePortalStmt(ClosePortalStmt *from)
1583 ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1585 COPY_STRING_FIELD(portalname);
1590 static ClusterStmt *
1591 _copyClusterStmt(ClusterStmt *from)
1593 ClusterStmt *newnode = makeNode(ClusterStmt);
1595 COPY_NODE_FIELD(relation);
1596 COPY_STRING_FIELD(indexname);
1602 _copyCopyStmt(CopyStmt *from)
1604 CopyStmt *newnode = makeNode(CopyStmt);
1606 COPY_NODE_FIELD(relation);
1607 COPY_NODE_FIELD(attlist);
1608 COPY_SCALAR_FIELD(is_from);
1609 COPY_STRING_FIELD(filename);
1610 COPY_NODE_FIELD(options);
1616 _copyCreateStmt(CreateStmt *from)
1618 CreateStmt *newnode = makeNode(CreateStmt);
1620 COPY_NODE_FIELD(relation);
1621 COPY_NODE_FIELD(tableElts);
1622 COPY_NODE_FIELD(inhRelations);
1623 COPY_NODE_FIELD(constraints);
1624 COPY_SCALAR_FIELD(hasoids);
1625 COPY_SCALAR_FIELD(oncommit);
1631 _copyDefineStmt(DefineStmt *from)
1633 DefineStmt *newnode = makeNode(DefineStmt);
1635 COPY_SCALAR_FIELD(defType);
1636 COPY_NODE_FIELD(defnames);
1637 COPY_NODE_FIELD(definition);
1643 _copyDropStmt(DropStmt *from)
1645 DropStmt *newnode = makeNode(DropStmt);
1647 COPY_NODE_FIELD(objects);
1648 COPY_SCALAR_FIELD(removeType);
1649 COPY_SCALAR_FIELD(behavior);
1654 static TruncateStmt *
1655 _copyTruncateStmt(TruncateStmt *from)
1657 TruncateStmt *newnode = makeNode(TruncateStmt);
1659 COPY_NODE_FIELD(relation);
1664 static CommentStmt *
1665 _copyCommentStmt(CommentStmt *from)
1667 CommentStmt *newnode = makeNode(CommentStmt);
1669 COPY_SCALAR_FIELD(objtype);
1670 COPY_NODE_FIELD(objname);
1671 COPY_NODE_FIELD(objargs);
1672 COPY_STRING_FIELD(comment);
1678 _copyFetchStmt(FetchStmt *from)
1680 FetchStmt *newnode = makeNode(FetchStmt);
1682 COPY_SCALAR_FIELD(direction);
1683 COPY_SCALAR_FIELD(howMany);
1684 COPY_STRING_FIELD(portalname);
1685 COPY_SCALAR_FIELD(ismove);
1691 _copyIndexStmt(IndexStmt *from)
1693 IndexStmt *newnode = makeNode(IndexStmt);
1695 COPY_STRING_FIELD(idxname);
1696 COPY_NODE_FIELD(relation);
1697 COPY_STRING_FIELD(accessMethod);
1698 COPY_NODE_FIELD(indexParams);
1699 COPY_NODE_FIELD(whereClause);
1700 COPY_NODE_FIELD(rangetable);
1701 COPY_SCALAR_FIELD(unique);
1702 COPY_SCALAR_FIELD(primary);
1703 COPY_SCALAR_FIELD(isconstraint);
1708 static CreateFunctionStmt *
1709 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1711 CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1713 COPY_SCALAR_FIELD(replace);
1714 COPY_NODE_FIELD(funcname);
1715 COPY_NODE_FIELD(argTypes);
1716 COPY_NODE_FIELD(returnType);
1717 COPY_NODE_FIELD(options);
1718 COPY_NODE_FIELD(withClause);
1723 static RemoveAggrStmt *
1724 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1726 RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1728 COPY_NODE_FIELD(aggname);
1729 COPY_NODE_FIELD(aggtype);
1730 COPY_SCALAR_FIELD(behavior);
1735 static RemoveFuncStmt *
1736 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1738 RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1740 COPY_NODE_FIELD(funcname);
1741 COPY_NODE_FIELD(args);
1742 COPY_SCALAR_FIELD(behavior);
1747 static RemoveOperStmt *
1748 _copyRemoveOperStmt(RemoveOperStmt *from)
1750 RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1752 COPY_NODE_FIELD(opname);
1753 COPY_NODE_FIELD(args);
1754 COPY_SCALAR_FIELD(behavior);
1759 static RemoveOpClassStmt *
1760 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
1762 RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
1764 COPY_NODE_FIELD(opclassname);
1765 COPY_STRING_FIELD(amname);
1766 COPY_SCALAR_FIELD(behavior);
1772 _copyRenameStmt(RenameStmt *from)
1774 RenameStmt *newnode = makeNode(RenameStmt);
1776 COPY_NODE_FIELD(relation);
1777 COPY_STRING_FIELD(oldname);
1778 COPY_STRING_FIELD(newname);
1779 COPY_SCALAR_FIELD(renameType);
1785 _copyRuleStmt(RuleStmt *from)
1787 RuleStmt *newnode = makeNode(RuleStmt);
1789 COPY_NODE_FIELD(relation);
1790 COPY_STRING_FIELD(rulename);
1791 COPY_NODE_FIELD(whereClause);
1792 COPY_SCALAR_FIELD(event);
1793 COPY_SCALAR_FIELD(instead);
1794 COPY_NODE_FIELD(actions);
1795 COPY_SCALAR_FIELD(replace);
1801 _copyNotifyStmt(NotifyStmt *from)
1803 NotifyStmt *newnode = makeNode(NotifyStmt);
1805 COPY_NODE_FIELD(relation);
1811 _copyListenStmt(ListenStmt *from)
1813 ListenStmt *newnode = makeNode(ListenStmt);
1815 COPY_NODE_FIELD(relation);
1820 static UnlistenStmt *
1821 _copyUnlistenStmt(UnlistenStmt *from)
1823 UnlistenStmt *newnode = makeNode(UnlistenStmt);
1825 COPY_NODE_FIELD(relation);
1830 static TransactionStmt *
1831 _copyTransactionStmt(TransactionStmt *from)
1833 TransactionStmt *newnode = makeNode(TransactionStmt);
1835 COPY_SCALAR_FIELD(command);
1836 COPY_NODE_FIELD(options);
1841 static CompositeTypeStmt *
1842 _copyCompositeTypeStmt(CompositeTypeStmt *from)
1844 CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
1846 COPY_NODE_FIELD(typevar);
1847 COPY_NODE_FIELD(coldeflist);
1853 _copyViewStmt(ViewStmt *from)
1855 ViewStmt *newnode = makeNode(ViewStmt);
1857 COPY_NODE_FIELD(view);
1858 COPY_NODE_FIELD(aliases);
1859 COPY_NODE_FIELD(query);
1860 COPY_SCALAR_FIELD(replace);
1866 _copyLoadStmt(LoadStmt *from)
1868 LoadStmt *newnode = makeNode(LoadStmt);
1870 COPY_STRING_FIELD(filename);
1875 static CreateDomainStmt *
1876 _copyCreateDomainStmt(CreateDomainStmt *from)
1878 CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
1880 COPY_NODE_FIELD(domainname);
1881 COPY_NODE_FIELD(typename);
1882 COPY_NODE_FIELD(constraints);
1887 static CreateOpClassStmt *
1888 _copyCreateOpClassStmt(CreateOpClassStmt *from)
1890 CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
1892 COPY_NODE_FIELD(opclassname);
1893 COPY_STRING_FIELD(amname);
1894 COPY_NODE_FIELD(datatype);
1895 COPY_NODE_FIELD(items);
1896 COPY_SCALAR_FIELD(isDefault);
1901 static CreateOpClassItem *
1902 _copyCreateOpClassItem(CreateOpClassItem *from)
1904 CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
1906 COPY_SCALAR_FIELD(itemtype);
1907 COPY_NODE_FIELD(name);
1908 COPY_NODE_FIELD(args);
1909 COPY_SCALAR_FIELD(number);
1910 COPY_SCALAR_FIELD(recheck);
1911 COPY_NODE_FIELD(storedtype);
1916 static CreatedbStmt *
1917 _copyCreatedbStmt(CreatedbStmt *from)
1919 CreatedbStmt *newnode = makeNode(CreatedbStmt);
1921 COPY_STRING_FIELD(dbname);
1922 COPY_NODE_FIELD(options);
1927 static AlterDatabaseSetStmt *
1928 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
1930 AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
1932 COPY_STRING_FIELD(dbname);
1933 COPY_STRING_FIELD(variable);
1934 COPY_NODE_FIELD(value);
1940 _copyDropdbStmt(DropdbStmt *from)
1942 DropdbStmt *newnode = makeNode(DropdbStmt);
1944 COPY_STRING_FIELD(dbname);
1950 _copyVacuumStmt(VacuumStmt *from)
1952 VacuumStmt *newnode = makeNode(VacuumStmt);
1954 COPY_SCALAR_FIELD(vacuum);
1955 COPY_SCALAR_FIELD(full);
1956 COPY_SCALAR_FIELD(analyze);
1957 COPY_SCALAR_FIELD(freeze);
1958 COPY_SCALAR_FIELD(verbose);
1959 COPY_NODE_FIELD(relation);
1960 COPY_NODE_FIELD(va_cols);
1965 static ExplainStmt *
1966 _copyExplainStmt(ExplainStmt *from)
1968 ExplainStmt *newnode = makeNode(ExplainStmt);
1970 COPY_NODE_FIELD(query);
1971 COPY_SCALAR_FIELD(verbose);
1972 COPY_SCALAR_FIELD(analyze);
1977 static CreateSeqStmt *
1978 _copyCreateSeqStmt(CreateSeqStmt *from)
1980 CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
1982 COPY_NODE_FIELD(sequence);
1983 COPY_NODE_FIELD(options);
1988 static VariableSetStmt *
1989 _copyVariableSetStmt(VariableSetStmt *from)
1991 VariableSetStmt *newnode = makeNode(VariableSetStmt);
1993 COPY_STRING_FIELD(name);
1994 COPY_NODE_FIELD(args);
1995 COPY_SCALAR_FIELD(is_local);
2000 static VariableShowStmt *
2001 _copyVariableShowStmt(VariableShowStmt *from)
2003 VariableShowStmt *newnode = makeNode(VariableShowStmt);
2005 COPY_STRING_FIELD(name);
2010 static VariableResetStmt *
2011 _copyVariableResetStmt(VariableResetStmt *from)
2013 VariableResetStmt *newnode = makeNode(VariableResetStmt);
2015 COPY_STRING_FIELD(name);
2020 static CreateTrigStmt *
2021 _copyCreateTrigStmt(CreateTrigStmt *from)
2023 CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2025 COPY_STRING_FIELD(trigname);
2026 COPY_NODE_FIELD(relation);
2027 COPY_NODE_FIELD(funcname);
2028 COPY_NODE_FIELD(args);
2029 COPY_SCALAR_FIELD(before);
2030 COPY_SCALAR_FIELD(row);
2031 strcpy(newnode->actions, from->actions); /* in-line string field */
2032 COPY_SCALAR_FIELD(isconstraint);
2033 COPY_SCALAR_FIELD(deferrable);
2034 COPY_SCALAR_FIELD(initdeferred);
2035 COPY_NODE_FIELD(constrrel);
2040 static DropPropertyStmt *
2041 _copyDropPropertyStmt(DropPropertyStmt *from)
2043 DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2045 COPY_NODE_FIELD(relation);
2046 COPY_STRING_FIELD(property);
2047 COPY_SCALAR_FIELD(removeType);
2048 COPY_SCALAR_FIELD(behavior);
2053 static CreatePLangStmt *
2054 _copyCreatePLangStmt(CreatePLangStmt *from)
2056 CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2058 COPY_STRING_FIELD(plname);
2059 COPY_NODE_FIELD(plhandler);
2060 COPY_NODE_FIELD(plvalidator);
2061 COPY_SCALAR_FIELD(pltrusted);
2066 static DropPLangStmt *
2067 _copyDropPLangStmt(DropPLangStmt *from)
2069 DropPLangStmt *newnode = makeNode(DropPLangStmt);
2071 COPY_STRING_FIELD(plname);
2072 COPY_SCALAR_FIELD(behavior);
2077 static CreateUserStmt *
2078 _copyCreateUserStmt(CreateUserStmt *from)
2080 CreateUserStmt *newnode = makeNode(CreateUserStmt);
2082 COPY_STRING_FIELD(user);
2083 COPY_NODE_FIELD(options);
2088 static AlterUserStmt *
2089 _copyAlterUserStmt(AlterUserStmt *from)
2091 AlterUserStmt *newnode = makeNode(AlterUserStmt);
2093 COPY_STRING_FIELD(user);
2094 COPY_NODE_FIELD(options);
2099 static AlterUserSetStmt *
2100 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2102 AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2104 COPY_STRING_FIELD(user);
2105 COPY_STRING_FIELD(variable);
2106 COPY_NODE_FIELD(value);
2111 static DropUserStmt *
2112 _copyDropUserStmt(DropUserStmt *from)
2114 DropUserStmt *newnode = makeNode(DropUserStmt);
2116 COPY_NODE_FIELD(users);
2122 _copyLockStmt(LockStmt *from)
2124 LockStmt *newnode = makeNode(LockStmt);
2126 COPY_NODE_FIELD(relations);
2127 COPY_SCALAR_FIELD(mode);
2132 static ConstraintsSetStmt *
2133 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2135 ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2137 COPY_NODE_FIELD(constraints);
2138 COPY_SCALAR_FIELD(deferred);
2143 static CreateGroupStmt *
2144 _copyCreateGroupStmt(CreateGroupStmt *from)
2146 CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2148 COPY_STRING_FIELD(name);
2149 COPY_NODE_FIELD(options);
2154 static AlterGroupStmt *
2155 _copyAlterGroupStmt(AlterGroupStmt *from)
2157 AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2159 COPY_STRING_FIELD(name);
2160 COPY_SCALAR_FIELD(action);
2161 COPY_NODE_FIELD(listUsers);
2166 static DropGroupStmt *
2167 _copyDropGroupStmt(DropGroupStmt *from)
2169 DropGroupStmt *newnode = makeNode(DropGroupStmt);
2171 COPY_STRING_FIELD(name);
2176 static ReindexStmt *
2177 _copyReindexStmt(ReindexStmt *from)
2179 ReindexStmt *newnode = makeNode(ReindexStmt);
2181 COPY_SCALAR_FIELD(reindexType);
2182 COPY_NODE_FIELD(relation);
2183 COPY_STRING_FIELD(name);
2184 COPY_SCALAR_FIELD(force);
2185 COPY_SCALAR_FIELD(all);
2190 static CreateSchemaStmt *
2191 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2193 CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2195 COPY_STRING_FIELD(schemaname);
2196 COPY_STRING_FIELD(authid);
2197 COPY_NODE_FIELD(schemaElts);
2202 static CreateConversionStmt *
2203 _copyCreateConversionStmt(CreateConversionStmt *from)
2205 CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2207 COPY_NODE_FIELD(conversion_name);
2208 COPY_STRING_FIELD(for_encoding_name);
2209 COPY_STRING_FIELD(to_encoding_name);
2210 COPY_NODE_FIELD(func_name);
2211 COPY_SCALAR_FIELD(def);
2216 static CreateCastStmt *
2217 _copyCreateCastStmt(CreateCastStmt *from)
2219 CreateCastStmt *newnode = makeNode(CreateCastStmt);
2221 COPY_NODE_FIELD(sourcetype);
2222 COPY_NODE_FIELD(targettype);
2223 COPY_NODE_FIELD(func);
2224 COPY_SCALAR_FIELD(context);
2229 static DropCastStmt *
2230 _copyDropCastStmt(DropCastStmt *from)
2232 DropCastStmt *newnode = makeNode(DropCastStmt);
2234 COPY_NODE_FIELD(sourcetype);
2235 COPY_NODE_FIELD(targettype);
2236 COPY_SCALAR_FIELD(behavior);
2241 static PrepareStmt *
2242 _copyPrepareStmt(PrepareStmt *from)
2244 PrepareStmt *newnode = makeNode(PrepareStmt);
2246 COPY_STRING_FIELD(name);
2247 COPY_NODE_FIELD(argtypes);
2248 COPY_INTLIST_FIELD(argtype_oids);
2249 COPY_NODE_FIELD(query);
2254 static ExecuteStmt *
2255 _copyExecuteStmt(ExecuteStmt *from)
2257 ExecuteStmt *newnode = makeNode(ExecuteStmt);
2259 COPY_STRING_FIELD(name);
2260 COPY_NODE_FIELD(into);
2261 COPY_NODE_FIELD(params);
2266 static DeallocateStmt *
2267 _copyDeallocateStmt(DeallocateStmt *from)
2269 DeallocateStmt *newnode = makeNode(DeallocateStmt);
2271 COPY_STRING_FIELD(name);
2277 /* ****************************************************************
2278 * pg_list.h copy functions
2279 * ****************************************************************
2283 _copyValue(Value *from)
2285 Value *newnode = makeNode(Value);
2287 /* See also _copyAConst when changing this code! */
2289 COPY_SCALAR_FIELD(type);
2293 COPY_SCALAR_FIELD(val.ival);
2298 COPY_STRING_FIELD(val.str);
2304 elog(ERROR, "_copyValue: unknown node type %d", from->type);
2313 * Create a copy of a Node tree or list. This is a "deep" copy: all
2314 * substructure is copied too, recursively.
2317 copyObject(void *from)
2324 switch (nodeTag(from))
2330 retval = _copyPlan(from);
2333 retval = _copyResult(from);
2336 retval = _copyAppend(from);
2339 retval = _copyScan(from);
2342 retval = _copySeqScan(from);
2345 retval = _copyIndexScan(from);
2348 retval = _copyTidScan(from);
2350 case T_SubqueryScan:
2351 retval = _copySubqueryScan(from);
2353 case T_FunctionScan:
2354 retval = _copyFunctionScan(from);
2357 retval = _copyJoin(from);
2360 retval = _copyNestLoop(from);
2363 retval = _copyMergeJoin(from);
2366 retval = _copyHashJoin(from);
2369 retval = _copyMaterial(from);
2372 retval = _copySort(from);
2375 retval = _copyGroup(from);
2378 retval = _copyAgg(from);
2381 retval = _copyUnique(from);
2384 retval = _copyHash(from);
2387 retval = _copySetOp(from);
2390 retval = _copyLimit(from);
2397 retval = _copyResdom(from);
2400 retval = _copyAlias(from);
2403 retval = _copyRangeVar(from);
2406 retval = _copyVar(from);
2409 retval = _copyConst(from);
2412 retval = _copyParam(from);
2415 retval = _copyAggref(from);
2418 retval = _copyArrayRef(from);
2421 retval = _copyFuncExpr(from);
2424 retval = _copyOpExpr(from);
2426 case T_DistinctExpr:
2427 retval = _copyDistinctExpr(from);
2430 retval = _copyBoolExpr(from);
2433 retval = _copySubLink(from);
2436 retval = _copySubPlan(from);
2439 retval = _copyFieldSelect(from);
2442 retval = _copyRelabelType(from);
2445 retval = _copyCaseExpr(from);
2448 retval = _copyCaseWhen(from);
2451 retval = _copyNullTest(from);
2454 retval = _copyBooleanTest(from);
2456 case T_ConstraintTest:
2457 retval = _copyConstraintTest(from);
2459 case T_ConstraintTestValue:
2460 retval = _copyConstraintTestValue(from);
2463 retval = _copyTargetEntry(from);
2466 retval = _copyRangeTblRef(from);
2469 retval = _copyJoinExpr(from);
2472 retval = _copyFromExpr(from);
2479 retval = _copyPathKeyItem(from);
2481 case T_RestrictInfo:
2482 retval = _copyRestrictInfo(from);
2485 retval = _copyJoinInfo(from);
2496 retval = _copyValue(from);
2504 /* rather ugly coding for speed... */
2505 /* Note the input list cannot be NIL if we got here. */
2506 nl = makeList1(copyObject(lfirst(list)));
2509 foreach(l, lnext(list))
2511 lnext(nl) = makeList1(copyObject(lfirst(l)));
2521 retval = _copyQuery(from);
2524 retval = _copyInsertStmt(from);
2527 retval = _copyDeleteStmt(from);
2530 retval = _copyUpdateStmt(from);
2533 retval = _copySelectStmt(from);
2535 case T_SetOperationStmt:
2536 retval = _copySetOperationStmt(from);
2538 case T_AlterTableStmt:
2539 retval = _copyAlterTableStmt(from);
2541 case T_AlterDomainStmt:
2542 retval = _copyAlterDomainStmt(from);
2545 retval = _copyGrantStmt(from);
2547 case T_ClosePortalStmt:
2548 retval = _copyClosePortalStmt(from);
2551 retval = _copyClusterStmt(from);
2554 retval = _copyCopyStmt(from);
2557 retval = _copyCreateStmt(from);
2560 retval = _copyDefineStmt(from);
2563 retval = _copyDropStmt(from);
2565 case T_TruncateStmt:
2566 retval = _copyTruncateStmt(from);
2569 retval = _copyCommentStmt(from);
2572 retval = _copyFetchStmt(from);
2575 retval = _copyIndexStmt(from);
2577 case T_CreateFunctionStmt:
2578 retval = _copyCreateFunctionStmt(from);
2580 case T_RemoveAggrStmt:
2581 retval = _copyRemoveAggrStmt(from);
2583 case T_RemoveFuncStmt:
2584 retval = _copyRemoveFuncStmt(from);
2586 case T_RemoveOperStmt:
2587 retval = _copyRemoveOperStmt(from);
2589 case T_RemoveOpClassStmt:
2590 retval = _copyRemoveOpClassStmt(from);
2593 retval = _copyRenameStmt(from);
2596 retval = _copyRuleStmt(from);
2599 retval = _copyNotifyStmt(from);
2602 retval = _copyListenStmt(from);
2604 case T_UnlistenStmt:
2605 retval = _copyUnlistenStmt(from);
2607 case T_TransactionStmt:
2608 retval = _copyTransactionStmt(from);
2610 case T_CompositeTypeStmt:
2611 retval = _copyCompositeTypeStmt(from);
2614 retval = _copyViewStmt(from);
2617 retval = _copyLoadStmt(from);
2619 case T_CreateDomainStmt:
2620 retval = _copyCreateDomainStmt(from);
2622 case T_CreateOpClassStmt:
2623 retval = _copyCreateOpClassStmt(from);
2625 case T_CreateOpClassItem:
2626 retval = _copyCreateOpClassItem(from);
2628 case T_CreatedbStmt:
2629 retval = _copyCreatedbStmt(from);
2631 case T_AlterDatabaseSetStmt:
2632 retval = _copyAlterDatabaseSetStmt(from);
2635 retval = _copyDropdbStmt(from);
2638 retval = _copyVacuumStmt(from);
2641 retval = _copyExplainStmt(from);
2643 case T_CreateSeqStmt:
2644 retval = _copyCreateSeqStmt(from);
2646 case T_VariableSetStmt:
2647 retval = _copyVariableSetStmt(from);
2649 case T_VariableShowStmt:
2650 retval = _copyVariableShowStmt(from);
2652 case T_VariableResetStmt:
2653 retval = _copyVariableResetStmt(from);
2655 case T_CreateTrigStmt:
2656 retval = _copyCreateTrigStmt(from);
2658 case T_DropPropertyStmt:
2659 retval = _copyDropPropertyStmt(from);
2661 case T_CreatePLangStmt:
2662 retval = _copyCreatePLangStmt(from);
2664 case T_DropPLangStmt:
2665 retval = _copyDropPLangStmt(from);
2667 case T_CreateUserStmt:
2668 retval = _copyCreateUserStmt(from);
2670 case T_AlterUserStmt:
2671 retval = _copyAlterUserStmt(from);
2673 case T_AlterUserSetStmt:
2674 retval = _copyAlterUserSetStmt(from);
2676 case T_DropUserStmt:
2677 retval = _copyDropUserStmt(from);
2680 retval = _copyLockStmt(from);
2682 case T_ConstraintsSetStmt:
2683 retval = _copyConstraintsSetStmt(from);
2685 case T_CreateGroupStmt:
2686 retval = _copyCreateGroupStmt(from);
2688 case T_AlterGroupStmt:
2689 retval = _copyAlterGroupStmt(from);
2691 case T_DropGroupStmt:
2692 retval = _copyDropGroupStmt(from);
2695 retval = _copyReindexStmt(from);
2697 case T_CheckPointStmt:
2698 retval = (void *) makeNode(CheckPointStmt);
2700 case T_CreateSchemaStmt:
2701 retval = _copyCreateSchemaStmt(from);
2703 case T_CreateConversionStmt:
2704 retval = _copyCreateConversionStmt(from);
2706 case T_CreateCastStmt:
2707 retval = _copyCreateCastStmt(from);
2709 case T_DropCastStmt:
2710 retval = _copyDropCastStmt(from);
2713 retval = _copyPrepareStmt(from);
2716 retval = _copyExecuteStmt(from);
2718 case T_DeallocateStmt:
2719 retval = _copyDeallocateStmt(from);
2723 retval = _copyAExpr(from);
2726 retval = _copyColumnRef(from);
2729 retval = _copyParamRef(from);
2732 retval = _copyAConst(from);
2735 retval = _copyFuncCall(from);
2738 retval = _copyAIndices(from);
2740 case T_ExprFieldSelect:
2741 retval = _copyExprFieldSelect(from);
2744 retval = _copyResTarget(from);
2747 retval = _copyTypeCast(from);
2750 retval = _copySortGroupBy(from);
2752 case T_RangeSubselect:
2753 retval = _copyRangeSubselect(from);
2755 case T_RangeFunction:
2756 retval = _copyRangeFunction(from);
2759 retval = _copyTypeName(from);
2762 retval = _copyIndexElem(from);
2765 retval = _copyColumnDef(from);
2768 retval = _copyConstraint(from);
2771 retval = _copyDefElem(from);
2773 case T_RangeTblEntry:
2774 retval = _copyRangeTblEntry(from);
2777 retval = _copySortClause(from);
2780 retval = _copyGroupClause(from);
2782 case T_FkConstraint:
2783 retval = _copyFkConstraint(from);
2786 retval = _copyPrivGrantee(from);
2788 case T_FuncWithArgs:
2789 retval = _copyFuncWithArgs(from);
2791 case T_InsertDefault:
2792 retval = _copyInsertDefault(from);
2796 elog(ERROR, "copyObject: don't know how to copy node type %d",
2798 retval = from; /* keep compiler quiet */