]> granicus.if.org Git - postgresql/blob - src/backend/nodes/copyfuncs.c
2f7642276cf959ea0a8bc378584cf6ae53f75c5b
[postgresql] / src / backend / nodes / copyfuncs.c
1 /*-------------------------------------------------------------------------
2  *
3  * copyfuncs.c
4  *        Copy functions for Postgres tree nodes.
5  *
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.
12  *
13  *
14  * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
15  * Portions Copyright (c) 1994, Regents of the University of California
16  *
17  * IDENTIFICATION
18  *        $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.305 2005/06/05 22:32:54 tgl Exp $
19  *
20  *-------------------------------------------------------------------------
21  */
22
23 #include "postgres.h"
24
25 #include "nodes/parsenodes.h"
26 #include "nodes/plannodes.h"
27 #include "nodes/relation.h"
28 #include "utils/datum.h"
29
30
31 /*
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'.
36  */
37
38 /* Copy a simple scalar field (int, float, bool, enum, etc) */
39 #define COPY_SCALAR_FIELD(fldname) \
40         (newnode->fldname = from->fldname)
41
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))
45
46 /* Copy a field that is a pointer to a Bitmapset */
47 #define COPY_BITMAPSET_FIELD(fldname) \
48         (newnode->fldname = bms_copy(from->fldname))
49
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)
53
54 /* Copy a field that is a pointer to a simple palloc'd object of size sz */
55 #define COPY_POINTER_FIELD(fldname, sz) \
56         do { \
57                 Size    _size = (sz); \
58                 newnode->fldname = palloc(_size); \
59                 memcpy(newnode->fldname, from->fldname, _size); \
60         } while (0)
61
62
63 /* ****************************************************************
64  *                                       plannodes.h copy functions
65  * ****************************************************************
66  */
67
68 /*
69  * CopyPlanFields
70  *
71  *              This function copies the fields of the Plan node.  It is used by
72  *              all the copy functions for classes which inherit from Plan.
73  */
74 static void
75 CopyPlanFields(Plan *from, Plan *newnode)
76 {
77         COPY_SCALAR_FIELD(startup_cost);
78         COPY_SCALAR_FIELD(total_cost);
79         COPY_SCALAR_FIELD(plan_rows);
80         COPY_SCALAR_FIELD(plan_width);
81         COPY_NODE_FIELD(targetlist);
82         COPY_NODE_FIELD(qual);
83         COPY_NODE_FIELD(lefttree);
84         COPY_NODE_FIELD(righttree);
85         COPY_NODE_FIELD(initPlan);
86         COPY_BITMAPSET_FIELD(extParam);
87         COPY_BITMAPSET_FIELD(allParam);
88         COPY_SCALAR_FIELD(nParamExec);
89 }
90
91 /*
92  * _copyPlan
93  */
94 static Plan *
95 _copyPlan(Plan *from)
96 {
97         Plan       *newnode = makeNode(Plan);
98
99         /*
100          * copy node superclass fields
101          */
102         CopyPlanFields(from, newnode);
103
104         return newnode;
105 }
106
107
108 /*
109  * _copyResult
110  */
111 static Result *
112 _copyResult(Result *from)
113 {
114         Result     *newnode = makeNode(Result);
115
116         /*
117          * copy node superclass fields
118          */
119         CopyPlanFields((Plan *) from, (Plan *) newnode);
120
121         /*
122          * copy remainder of node
123          */
124         COPY_NODE_FIELD(resconstantqual);
125
126         return newnode;
127 }
128
129 /*
130  * _copyAppend
131  */
132 static Append *
133 _copyAppend(Append *from)
134 {
135         Append     *newnode = makeNode(Append);
136
137         /*
138          * copy node superclass fields
139          */
140         CopyPlanFields((Plan *) from, (Plan *) newnode);
141
142         /*
143          * copy remainder of node
144          */
145         COPY_NODE_FIELD(appendplans);
146         COPY_SCALAR_FIELD(isTarget);
147
148         return newnode;
149 }
150
151 /*
152  * _copyBitmapAnd
153  */
154 static BitmapAnd *
155 _copyBitmapAnd(BitmapAnd *from)
156 {
157         BitmapAnd          *newnode = makeNode(BitmapAnd);
158
159         /*
160          * copy node superclass fields
161          */
162         CopyPlanFields((Plan *) from, (Plan *) newnode);
163
164         /*
165          * copy remainder of node
166          */
167         COPY_NODE_FIELD(bitmapplans);
168
169         return newnode;
170 }
171
172 /*
173  * _copyBitmapOr
174  */
175 static BitmapOr *
176 _copyBitmapOr(BitmapOr *from)
177 {
178         BitmapOr           *newnode = makeNode(BitmapOr);
179
180         /*
181          * copy node superclass fields
182          */
183         CopyPlanFields((Plan *) from, (Plan *) newnode);
184
185         /*
186          * copy remainder of node
187          */
188         COPY_NODE_FIELD(bitmapplans);
189
190         return newnode;
191 }
192
193
194 /*
195  * CopyScanFields
196  *
197  *              This function copies the fields of the Scan node.  It is used by
198  *              all the copy functions for classes which inherit from Scan.
199  */
200 static void
201 CopyScanFields(Scan *from, Scan *newnode)
202 {
203         CopyPlanFields((Plan *) from, (Plan *) newnode);
204
205         COPY_SCALAR_FIELD(scanrelid);
206 }
207
208 /*
209  * _copyScan
210  */
211 static Scan *
212 _copyScan(Scan *from)
213 {
214         Scan       *newnode = makeNode(Scan);
215
216         /*
217          * copy node superclass fields
218          */
219         CopyScanFields((Scan *) from, (Scan *) newnode);
220
221         return newnode;
222 }
223
224 /*
225  * _copySeqScan
226  */
227 static SeqScan *
228 _copySeqScan(SeqScan *from)
229 {
230         SeqScan    *newnode = makeNode(SeqScan);
231
232         /*
233          * copy node superclass fields
234          */
235         CopyScanFields((Scan *) from, (Scan *) newnode);
236
237         return newnode;
238 }
239
240 /*
241  * _copyIndexScan
242  */
243 static IndexScan *
244 _copyIndexScan(IndexScan *from)
245 {
246         IndexScan  *newnode = makeNode(IndexScan);
247
248         /*
249          * copy node superclass fields
250          */
251         CopyScanFields((Scan *) from, (Scan *) newnode);
252
253         /*
254          * copy remainder of node
255          */
256         COPY_SCALAR_FIELD(indexid);
257         COPY_NODE_FIELD(indexqual);
258         COPY_NODE_FIELD(indexqualorig);
259         COPY_NODE_FIELD(indexstrategy);
260         COPY_NODE_FIELD(indexsubtype);
261         COPY_SCALAR_FIELD(indexorderdir);
262
263         return newnode;
264 }
265
266 /*
267  * _copyBitmapIndexScan
268  */
269 static BitmapIndexScan *
270 _copyBitmapIndexScan(BitmapIndexScan *from)
271 {
272         BitmapIndexScan  *newnode = makeNode(BitmapIndexScan);
273
274         /*
275          * copy node superclass fields
276          */
277         CopyScanFields((Scan *) from, (Scan *) newnode);
278
279         /*
280          * copy remainder of node
281          */
282         COPY_SCALAR_FIELD(indexid);
283         COPY_NODE_FIELD(indexqual);
284         COPY_NODE_FIELD(indexqualorig);
285         COPY_NODE_FIELD(indexstrategy);
286         COPY_NODE_FIELD(indexsubtype);
287
288         return newnode;
289 }
290
291 /*
292  * _copyBitmapHeapScan
293  */
294 static BitmapHeapScan *
295 _copyBitmapHeapScan(BitmapHeapScan *from)
296 {
297         BitmapHeapScan  *newnode = makeNode(BitmapHeapScan);
298
299         /*
300          * copy node superclass fields
301          */
302         CopyScanFields((Scan *) from, (Scan *) newnode);
303
304         /*
305          * copy remainder of node
306          */
307         COPY_NODE_FIELD(bitmapqualorig);
308
309         return newnode;
310 }
311
312 /*
313  * _copyTidScan
314  */
315 static TidScan *
316 _copyTidScan(TidScan *from)
317 {
318         TidScan    *newnode = makeNode(TidScan);
319
320         /*
321          * copy node superclass fields
322          */
323         CopyScanFields((Scan *) from, (Scan *) newnode);
324
325         /*
326          * copy remainder of node
327          */
328         COPY_NODE_FIELD(tideval);
329
330         return newnode;
331 }
332
333 /*
334  * _copySubqueryScan
335  */
336 static SubqueryScan *
337 _copySubqueryScan(SubqueryScan *from)
338 {
339         SubqueryScan *newnode = makeNode(SubqueryScan);
340
341         /*
342          * copy node superclass fields
343          */
344         CopyScanFields((Scan *) from, (Scan *) newnode);
345
346         /*
347          * copy remainder of node
348          */
349         COPY_NODE_FIELD(subplan);
350
351         return newnode;
352 }
353
354 /*
355  * _copyFunctionScan
356  */
357 static FunctionScan *
358 _copyFunctionScan(FunctionScan *from)
359 {
360         FunctionScan *newnode = makeNode(FunctionScan);
361
362         /*
363          * copy node superclass fields
364          */
365         CopyScanFields((Scan *) from, (Scan *) newnode);
366
367         return newnode;
368 }
369
370 /*
371  * CopyJoinFields
372  *
373  *              This function copies the fields of the Join node.  It is used by
374  *              all the copy functions for classes which inherit from Join.
375  */
376 static void
377 CopyJoinFields(Join *from, Join *newnode)
378 {
379         CopyPlanFields((Plan *) from, (Plan *) newnode);
380
381         COPY_SCALAR_FIELD(jointype);
382         COPY_NODE_FIELD(joinqual);
383 }
384
385
386 /*
387  * _copyJoin
388  */
389 static Join *
390 _copyJoin(Join *from)
391 {
392         Join       *newnode = makeNode(Join);
393
394         /*
395          * copy node superclass fields
396          */
397         CopyJoinFields(from, newnode);
398
399         return newnode;
400 }
401
402
403 /*
404  * _copyNestLoop
405  */
406 static NestLoop *
407 _copyNestLoop(NestLoop *from)
408 {
409         NestLoop   *newnode = makeNode(NestLoop);
410
411         /*
412          * copy node superclass fields
413          */
414         CopyJoinFields((Join *) from, (Join *) newnode);
415
416         return newnode;
417 }
418
419
420 /*
421  * _copyMergeJoin
422  */
423 static MergeJoin *
424 _copyMergeJoin(MergeJoin *from)
425 {
426         MergeJoin  *newnode = makeNode(MergeJoin);
427
428         /*
429          * copy node superclass fields
430          */
431         CopyJoinFields((Join *) from, (Join *) newnode);
432
433         /*
434          * copy remainder of node
435          */
436         COPY_NODE_FIELD(mergeclauses);
437
438         return newnode;
439 }
440
441 /*
442  * _copyHashJoin
443  */
444 static HashJoin *
445 _copyHashJoin(HashJoin *from)
446 {
447         HashJoin   *newnode = makeNode(HashJoin);
448
449         /*
450          * copy node superclass fields
451          */
452         CopyJoinFields((Join *) from, (Join *) newnode);
453
454         /*
455          * copy remainder of node
456          */
457         COPY_NODE_FIELD(hashclauses);
458
459         return newnode;
460 }
461
462
463 /*
464  * _copyMaterial
465  */
466 static Material *
467 _copyMaterial(Material *from)
468 {
469         Material   *newnode = makeNode(Material);
470
471         /*
472          * copy node superclass fields
473          */
474         CopyPlanFields((Plan *) from, (Plan *) newnode);
475
476         return newnode;
477 }
478
479
480 /*
481  * _copySort
482  */
483 static Sort *
484 _copySort(Sort *from)
485 {
486         Sort       *newnode = makeNode(Sort);
487
488         /*
489          * copy node superclass fields
490          */
491         CopyPlanFields((Plan *) from, (Plan *) newnode);
492
493         COPY_SCALAR_FIELD(numCols);
494         COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
495         COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
496
497         return newnode;
498 }
499
500
501 /*
502  * _copyGroup
503  */
504 static Group *
505 _copyGroup(Group *from)
506 {
507         Group      *newnode = makeNode(Group);
508
509         CopyPlanFields((Plan *) from, (Plan *) newnode);
510
511         COPY_SCALAR_FIELD(numCols);
512         COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
513
514         return newnode;
515 }
516
517 /*
518  * _copyAgg
519  */
520 static Agg *
521 _copyAgg(Agg *from)
522 {
523         Agg                *newnode = makeNode(Agg);
524
525         CopyPlanFields((Plan *) from, (Plan *) newnode);
526
527         COPY_SCALAR_FIELD(aggstrategy);
528         COPY_SCALAR_FIELD(numCols);
529         if (from->numCols > 0)
530                 COPY_POINTER_FIELD(grpColIdx, from->numCols * sizeof(AttrNumber));
531         COPY_SCALAR_FIELD(numGroups);
532
533         return newnode;
534 }
535
536 /*
537  * _copyUnique
538  */
539 static Unique *
540 _copyUnique(Unique *from)
541 {
542         Unique     *newnode = makeNode(Unique);
543
544         /*
545          * copy node superclass fields
546          */
547         CopyPlanFields((Plan *) from, (Plan *) newnode);
548
549         /*
550          * copy remainder of node
551          */
552         COPY_SCALAR_FIELD(numCols);
553         COPY_POINTER_FIELD(uniqColIdx, from->numCols * sizeof(AttrNumber));
554
555         return newnode;
556 }
557
558 /*
559  * _copyHash
560  */
561 static Hash *
562 _copyHash(Hash *from)
563 {
564         Hash       *newnode = makeNode(Hash);
565
566         /*
567          * copy node superclass fields
568          */
569         CopyPlanFields((Plan *) from, (Plan *) newnode);
570
571         /*
572          * copy remainder of node
573          */
574
575         return newnode;
576 }
577
578 /*
579  * _copySetOp
580  */
581 static SetOp *
582 _copySetOp(SetOp *from)
583 {
584         SetOp      *newnode = makeNode(SetOp);
585
586         /*
587          * copy node superclass fields
588          */
589         CopyPlanFields((Plan *) from, (Plan *) newnode);
590
591         /*
592          * copy remainder of node
593          */
594         COPY_SCALAR_FIELD(cmd);
595         COPY_SCALAR_FIELD(numCols);
596         COPY_POINTER_FIELD(dupColIdx, from->numCols * sizeof(AttrNumber));
597         COPY_SCALAR_FIELD(flagColIdx);
598
599         return newnode;
600 }
601
602 /*
603  * _copyLimit
604  */
605 static Limit *
606 _copyLimit(Limit *from)
607 {
608         Limit      *newnode = makeNode(Limit);
609
610         /*
611          * copy node superclass fields
612          */
613         CopyPlanFields((Plan *) from, (Plan *) newnode);
614
615         /*
616          * copy remainder of node
617          */
618         COPY_NODE_FIELD(limitOffset);
619         COPY_NODE_FIELD(limitCount);
620
621         return newnode;
622 }
623
624 /* ****************************************************************
625  *                                         primnodes.h copy functions
626  * ****************************************************************
627  */
628
629 /*
630  * _copyAlias
631  */
632 static Alias *
633 _copyAlias(Alias *from)
634 {
635         Alias      *newnode = makeNode(Alias);
636
637         COPY_STRING_FIELD(aliasname);
638         COPY_NODE_FIELD(colnames);
639
640         return newnode;
641 }
642
643 /*
644  * _copyRangeVar
645  */
646 static RangeVar *
647 _copyRangeVar(RangeVar *from)
648 {
649         RangeVar   *newnode = makeNode(RangeVar);
650
651         COPY_STRING_FIELD(catalogname);
652         COPY_STRING_FIELD(schemaname);
653         COPY_STRING_FIELD(relname);
654         COPY_SCALAR_FIELD(inhOpt);
655         COPY_SCALAR_FIELD(istemp);
656         COPY_NODE_FIELD(alias);
657
658         return newnode;
659 }
660
661 /*
662  * We don't need a _copyExpr because Expr is an abstract supertype which
663  * should never actually get instantiated.      Also, since it has no common
664  * fields except NodeTag, there's no need for a helper routine to factor
665  * out copying the common fields...
666  */
667
668 /*
669  * _copyVar
670  */
671 static Var *
672 _copyVar(Var *from)
673 {
674         Var                *newnode = makeNode(Var);
675
676         COPY_SCALAR_FIELD(varno);
677         COPY_SCALAR_FIELD(varattno);
678         COPY_SCALAR_FIELD(vartype);
679         COPY_SCALAR_FIELD(vartypmod);
680         COPY_SCALAR_FIELD(varlevelsup);
681         COPY_SCALAR_FIELD(varnoold);
682         COPY_SCALAR_FIELD(varoattno);
683
684         return newnode;
685 }
686
687 /*
688  * _copyConst
689  */
690 static Const *
691 _copyConst(Const *from)
692 {
693         Const      *newnode = makeNode(Const);
694
695         COPY_SCALAR_FIELD(consttype);
696         COPY_SCALAR_FIELD(constlen);
697
698         if (from->constbyval || from->constisnull)
699         {
700                 /*
701                  * passed by value so just copy the datum. Also, don't try to copy
702                  * struct when value is null!
703                  */
704                 newnode->constvalue = from->constvalue;
705         }
706         else
707         {
708                 /*
709                  * passed by reference.  We need a palloc'd copy.
710                  */
711                 newnode->constvalue = datumCopy(from->constvalue,
712                                                                                 from->constbyval,
713                                                                                 from->constlen);
714         }
715
716         COPY_SCALAR_FIELD(constisnull);
717         COPY_SCALAR_FIELD(constbyval);
718
719         return newnode;
720 }
721
722 /*
723  * _copyParam
724  */
725 static Param *
726 _copyParam(Param *from)
727 {
728         Param      *newnode = makeNode(Param);
729
730         COPY_SCALAR_FIELD(paramkind);
731         COPY_SCALAR_FIELD(paramid);
732         COPY_STRING_FIELD(paramname);
733         COPY_SCALAR_FIELD(paramtype);
734
735         return newnode;
736 }
737
738 /*
739  * _copyAggref
740  */
741 static Aggref *
742 _copyAggref(Aggref *from)
743 {
744         Aggref     *newnode = makeNode(Aggref);
745
746         COPY_SCALAR_FIELD(aggfnoid);
747         COPY_SCALAR_FIELD(aggtype);
748         COPY_NODE_FIELD(target);
749         COPY_SCALAR_FIELD(agglevelsup);
750         COPY_SCALAR_FIELD(aggstar);
751         COPY_SCALAR_FIELD(aggdistinct);
752
753         return newnode;
754 }
755
756 /*
757  * _copyArrayRef
758  */
759 static ArrayRef *
760 _copyArrayRef(ArrayRef *from)
761 {
762         ArrayRef   *newnode = makeNode(ArrayRef);
763
764         COPY_SCALAR_FIELD(refrestype);
765         COPY_SCALAR_FIELD(refarraytype);
766         COPY_SCALAR_FIELD(refelemtype);
767         COPY_NODE_FIELD(refupperindexpr);
768         COPY_NODE_FIELD(reflowerindexpr);
769         COPY_NODE_FIELD(refexpr);
770         COPY_NODE_FIELD(refassgnexpr);
771
772         return newnode;
773 }
774
775 /*
776  * _copyFuncExpr
777  */
778 static FuncExpr *
779 _copyFuncExpr(FuncExpr *from)
780 {
781         FuncExpr   *newnode = makeNode(FuncExpr);
782
783         COPY_SCALAR_FIELD(funcid);
784         COPY_SCALAR_FIELD(funcresulttype);
785         COPY_SCALAR_FIELD(funcretset);
786         COPY_SCALAR_FIELD(funcformat);
787         COPY_NODE_FIELD(args);
788
789         return newnode;
790 }
791
792 /*
793  * _copyOpExpr
794  */
795 static OpExpr *
796 _copyOpExpr(OpExpr *from)
797 {
798         OpExpr     *newnode = makeNode(OpExpr);
799
800         COPY_SCALAR_FIELD(opno);
801         COPY_SCALAR_FIELD(opfuncid);
802         COPY_SCALAR_FIELD(opresulttype);
803         COPY_SCALAR_FIELD(opretset);
804         COPY_NODE_FIELD(args);
805
806         return newnode;
807 }
808
809 /*
810  * _copyDistinctExpr (same as OpExpr)
811  */
812 static DistinctExpr *
813 _copyDistinctExpr(DistinctExpr *from)
814 {
815         DistinctExpr *newnode = makeNode(DistinctExpr);
816
817         COPY_SCALAR_FIELD(opno);
818         COPY_SCALAR_FIELD(opfuncid);
819         COPY_SCALAR_FIELD(opresulttype);
820         COPY_SCALAR_FIELD(opretset);
821         COPY_NODE_FIELD(args);
822
823         return newnode;
824 }
825
826 /*
827  * _copyScalarArrayOpExpr
828  */
829 static ScalarArrayOpExpr *
830 _copyScalarArrayOpExpr(ScalarArrayOpExpr *from)
831 {
832         ScalarArrayOpExpr *newnode = makeNode(ScalarArrayOpExpr);
833
834         COPY_SCALAR_FIELD(opno);
835         COPY_SCALAR_FIELD(opfuncid);
836         COPY_SCALAR_FIELD(useOr);
837         COPY_NODE_FIELD(args);
838
839         return newnode;
840 }
841
842 /*
843  * _copyBoolExpr
844  */
845 static BoolExpr *
846 _copyBoolExpr(BoolExpr *from)
847 {
848         BoolExpr   *newnode = makeNode(BoolExpr);
849
850         COPY_SCALAR_FIELD(boolop);
851         COPY_NODE_FIELD(args);
852
853         return newnode;
854 }
855
856 /*
857  * _copySubLink
858  */
859 static SubLink *
860 _copySubLink(SubLink *from)
861 {
862         SubLink    *newnode = makeNode(SubLink);
863
864         COPY_SCALAR_FIELD(subLinkType);
865         COPY_SCALAR_FIELD(useOr);
866         COPY_NODE_FIELD(lefthand);
867         COPY_NODE_FIELD(operName);
868         COPY_NODE_FIELD(operOids);
869         COPY_NODE_FIELD(subselect);
870
871         return newnode;
872 }
873
874 /*
875  * _copySubPlan
876  */
877 static SubPlan *
878 _copySubPlan(SubPlan *from)
879 {
880         SubPlan    *newnode = makeNode(SubPlan);
881
882         COPY_SCALAR_FIELD(subLinkType);
883         COPY_SCALAR_FIELD(useOr);
884         COPY_NODE_FIELD(exprs);
885         COPY_NODE_FIELD(paramIds);
886         COPY_NODE_FIELD(plan);
887         COPY_SCALAR_FIELD(plan_id);
888         COPY_NODE_FIELD(rtable);
889         COPY_SCALAR_FIELD(useHashTable);
890         COPY_SCALAR_FIELD(unknownEqFalse);
891         COPY_NODE_FIELD(setParam);
892         COPY_NODE_FIELD(parParam);
893         COPY_NODE_FIELD(args);
894
895         return newnode;
896 }
897
898 /*
899  * _copyFieldSelect
900  */
901 static FieldSelect *
902 _copyFieldSelect(FieldSelect *from)
903 {
904         FieldSelect *newnode = makeNode(FieldSelect);
905
906         COPY_NODE_FIELD(arg);
907         COPY_SCALAR_FIELD(fieldnum);
908         COPY_SCALAR_FIELD(resulttype);
909         COPY_SCALAR_FIELD(resulttypmod);
910
911         return newnode;
912 }
913
914 /*
915  * _copyFieldStore
916  */
917 static FieldStore *
918 _copyFieldStore(FieldStore *from)
919 {
920         FieldStore *newnode = makeNode(FieldStore);
921
922         COPY_NODE_FIELD(arg);
923         COPY_NODE_FIELD(newvals);
924         COPY_NODE_FIELD(fieldnums);
925         COPY_SCALAR_FIELD(resulttype);
926
927         return newnode;
928 }
929
930 /*
931  * _copyRelabelType
932  */
933 static RelabelType *
934 _copyRelabelType(RelabelType *from)
935 {
936         RelabelType *newnode = makeNode(RelabelType);
937
938         COPY_NODE_FIELD(arg);
939         COPY_SCALAR_FIELD(resulttype);
940         COPY_SCALAR_FIELD(resulttypmod);
941         COPY_SCALAR_FIELD(relabelformat);
942
943         return newnode;
944 }
945
946 /*
947  * _copyConvertRowtypeExpr
948  */
949 static ConvertRowtypeExpr *
950 _copyConvertRowtypeExpr(ConvertRowtypeExpr *from)
951 {
952         ConvertRowtypeExpr *newnode = makeNode(ConvertRowtypeExpr);
953
954         COPY_NODE_FIELD(arg);
955         COPY_SCALAR_FIELD(resulttype);
956         COPY_SCALAR_FIELD(convertformat);
957
958         return newnode;
959 }
960
961 /*
962  * _copyCaseExpr
963  */
964 static CaseExpr *
965 _copyCaseExpr(CaseExpr *from)
966 {
967         CaseExpr   *newnode = makeNode(CaseExpr);
968
969         COPY_SCALAR_FIELD(casetype);
970         COPY_NODE_FIELD(arg);
971         COPY_NODE_FIELD(args);
972         COPY_NODE_FIELD(defresult);
973
974         return newnode;
975 }
976
977 /*
978  * _copyCaseWhen
979  */
980 static CaseWhen *
981 _copyCaseWhen(CaseWhen *from)
982 {
983         CaseWhen   *newnode = makeNode(CaseWhen);
984
985         COPY_NODE_FIELD(expr);
986         COPY_NODE_FIELD(result);
987
988         return newnode;
989 }
990
991 /*
992  * _copyCaseTestExpr
993  */
994 static CaseTestExpr *
995 _copyCaseTestExpr(CaseTestExpr *from)
996 {
997         CaseTestExpr *newnode = makeNode(CaseTestExpr);
998
999         COPY_SCALAR_FIELD(typeId);
1000         COPY_SCALAR_FIELD(typeMod);
1001
1002         return newnode;
1003 }
1004
1005 /*
1006  * _copyArrayExpr
1007  */
1008 static ArrayExpr *
1009 _copyArrayExpr(ArrayExpr *from)
1010 {
1011         ArrayExpr  *newnode = makeNode(ArrayExpr);
1012
1013         COPY_SCALAR_FIELD(array_typeid);
1014         COPY_SCALAR_FIELD(element_typeid);
1015         COPY_NODE_FIELD(elements);
1016         COPY_SCALAR_FIELD(multidims);
1017
1018         return newnode;
1019 }
1020
1021 /*
1022  * _copyRowExpr
1023  */
1024 static RowExpr *
1025 _copyRowExpr(RowExpr *from)
1026 {
1027         RowExpr    *newnode = makeNode(RowExpr);
1028
1029         COPY_NODE_FIELD(args);
1030         COPY_SCALAR_FIELD(row_typeid);
1031         COPY_SCALAR_FIELD(row_format);
1032
1033         return newnode;
1034 }
1035
1036 /*
1037  * _copyCoalesceExpr
1038  */
1039 static CoalesceExpr *
1040 _copyCoalesceExpr(CoalesceExpr *from)
1041 {
1042         CoalesceExpr *newnode = makeNode(CoalesceExpr);
1043
1044         COPY_SCALAR_FIELD(coalescetype);
1045         COPY_NODE_FIELD(args);
1046
1047         return newnode;
1048 }
1049
1050 /*
1051  * _copyNullIfExpr (same as OpExpr)
1052  */
1053 static NullIfExpr *
1054 _copyNullIfExpr(NullIfExpr *from)
1055 {
1056         NullIfExpr *newnode = makeNode(NullIfExpr);
1057
1058         COPY_SCALAR_FIELD(opno);
1059         COPY_SCALAR_FIELD(opfuncid);
1060         COPY_SCALAR_FIELD(opresulttype);
1061         COPY_SCALAR_FIELD(opretset);
1062         COPY_NODE_FIELD(args);
1063
1064         return newnode;
1065 }
1066
1067 /*
1068  * _copyNullTest
1069  */
1070 static NullTest *
1071 _copyNullTest(NullTest *from)
1072 {
1073         NullTest   *newnode = makeNode(NullTest);
1074
1075         COPY_NODE_FIELD(arg);
1076         COPY_SCALAR_FIELD(nulltesttype);
1077
1078         return newnode;
1079 }
1080
1081 /*
1082  * _copyBooleanTest
1083  */
1084 static BooleanTest *
1085 _copyBooleanTest(BooleanTest *from)
1086 {
1087         BooleanTest *newnode = makeNode(BooleanTest);
1088
1089         COPY_NODE_FIELD(arg);
1090         COPY_SCALAR_FIELD(booltesttype);
1091
1092         return newnode;
1093 }
1094
1095 /*
1096  * _copyCoerceToDomain
1097  */
1098 static CoerceToDomain *
1099 _copyCoerceToDomain(CoerceToDomain *from)
1100 {
1101         CoerceToDomain *newnode = makeNode(CoerceToDomain);
1102
1103         COPY_NODE_FIELD(arg);
1104         COPY_SCALAR_FIELD(resulttype);
1105         COPY_SCALAR_FIELD(resulttypmod);
1106         COPY_SCALAR_FIELD(coercionformat);
1107
1108         return newnode;
1109 }
1110
1111 /*
1112  * _copyCoerceToDomainValue
1113  */
1114 static CoerceToDomainValue *
1115 _copyCoerceToDomainValue(CoerceToDomainValue *from)
1116 {
1117         CoerceToDomainValue *newnode = makeNode(CoerceToDomainValue);
1118
1119         COPY_SCALAR_FIELD(typeId);
1120         COPY_SCALAR_FIELD(typeMod);
1121
1122         return newnode;
1123 }
1124
1125 /*
1126  * _copySetToDefault
1127  */
1128 static SetToDefault *
1129 _copySetToDefault(SetToDefault *from)
1130 {
1131         SetToDefault *newnode = makeNode(SetToDefault);
1132
1133         COPY_SCALAR_FIELD(typeId);
1134         COPY_SCALAR_FIELD(typeMod);
1135
1136         return newnode;
1137 }
1138
1139 /*
1140  * _copyTargetEntry
1141  */
1142 static TargetEntry *
1143 _copyTargetEntry(TargetEntry *from)
1144 {
1145         TargetEntry *newnode = makeNode(TargetEntry);
1146
1147         COPY_NODE_FIELD(expr);
1148         COPY_SCALAR_FIELD(resno);
1149         COPY_STRING_FIELD(resname);
1150         COPY_SCALAR_FIELD(ressortgroupref);
1151         COPY_SCALAR_FIELD(resorigtbl);
1152         COPY_SCALAR_FIELD(resorigcol);
1153         COPY_SCALAR_FIELD(resjunk);
1154
1155         return newnode;
1156 }
1157
1158 /*
1159  * _copyRangeTblRef
1160  */
1161 static RangeTblRef *
1162 _copyRangeTblRef(RangeTblRef *from)
1163 {
1164         RangeTblRef *newnode = makeNode(RangeTblRef);
1165
1166         COPY_SCALAR_FIELD(rtindex);
1167
1168         return newnode;
1169 }
1170
1171 /*
1172  * _copyJoinExpr
1173  */
1174 static JoinExpr *
1175 _copyJoinExpr(JoinExpr *from)
1176 {
1177         JoinExpr   *newnode = makeNode(JoinExpr);
1178
1179         COPY_SCALAR_FIELD(jointype);
1180         COPY_SCALAR_FIELD(isNatural);
1181         COPY_NODE_FIELD(larg);
1182         COPY_NODE_FIELD(rarg);
1183         COPY_NODE_FIELD(using);
1184         COPY_NODE_FIELD(quals);
1185         COPY_NODE_FIELD(alias);
1186         COPY_SCALAR_FIELD(rtindex);
1187
1188         return newnode;
1189 }
1190
1191 /*
1192  * _copyFromExpr
1193  */
1194 static FromExpr *
1195 _copyFromExpr(FromExpr *from)
1196 {
1197         FromExpr   *newnode = makeNode(FromExpr);
1198
1199         COPY_NODE_FIELD(fromlist);
1200         COPY_NODE_FIELD(quals);
1201
1202         return newnode;
1203 }
1204
1205 /* ****************************************************************
1206  *                                              relation.h copy functions
1207  *
1208  * We don't support copying RelOptInfo, IndexOptInfo, or Path nodes.
1209  * There are some subsidiary structs that are useful to copy, though.
1210  * ****************************************************************
1211  */
1212
1213 /*
1214  * _copyPathKeyItem
1215  */
1216 static PathKeyItem *
1217 _copyPathKeyItem(PathKeyItem *from)
1218 {
1219         PathKeyItem *newnode = makeNode(PathKeyItem);
1220
1221         COPY_NODE_FIELD(key);
1222         COPY_SCALAR_FIELD(sortop);
1223
1224         return newnode;
1225 }
1226
1227 /*
1228  * _copyRestrictInfo
1229  */
1230 static RestrictInfo *
1231 _copyRestrictInfo(RestrictInfo *from)
1232 {
1233         RestrictInfo *newnode = makeNode(RestrictInfo);
1234
1235         COPY_NODE_FIELD(clause);
1236         COPY_SCALAR_FIELD(is_pushed_down);
1237         COPY_SCALAR_FIELD(valid_everywhere);
1238         COPY_SCALAR_FIELD(can_join);
1239         COPY_BITMAPSET_FIELD(clause_relids);
1240         COPY_BITMAPSET_FIELD(left_relids);
1241         COPY_BITMAPSET_FIELD(right_relids);
1242         COPY_NODE_FIELD(orclause);
1243         COPY_SCALAR_FIELD(eval_cost);
1244         COPY_SCALAR_FIELD(this_selec);
1245         COPY_SCALAR_FIELD(mergejoinoperator);
1246         COPY_SCALAR_FIELD(left_sortop);
1247         COPY_SCALAR_FIELD(right_sortop);
1248
1249         /*
1250          * Do not copy pathkeys, since they'd not be canonical in a copied
1251          * query
1252          */
1253         newnode->left_pathkey = NIL;
1254         newnode->right_pathkey = NIL;
1255
1256         COPY_SCALAR_FIELD(left_mergescansel);
1257         COPY_SCALAR_FIELD(right_mergescansel);
1258         COPY_SCALAR_FIELD(hashjoinoperator);
1259         COPY_SCALAR_FIELD(left_bucketsize);
1260         COPY_SCALAR_FIELD(right_bucketsize);
1261
1262         return newnode;
1263 }
1264
1265 /*
1266  * _copyJoinInfo
1267  */
1268 static JoinInfo *
1269 _copyJoinInfo(JoinInfo *from)
1270 {
1271         JoinInfo   *newnode = makeNode(JoinInfo);
1272
1273         COPY_BITMAPSET_FIELD(unjoined_relids);
1274         COPY_NODE_FIELD(jinfo_restrictinfo);
1275
1276         return newnode;
1277 }
1278
1279 /*
1280  * _copyInClauseInfo
1281  */
1282 static InClauseInfo *
1283 _copyInClauseInfo(InClauseInfo *from)
1284 {
1285         InClauseInfo *newnode = makeNode(InClauseInfo);
1286
1287         COPY_BITMAPSET_FIELD(lefthand);
1288         COPY_BITMAPSET_FIELD(righthand);
1289         COPY_NODE_FIELD(sub_targetlist);
1290
1291         return newnode;
1292 }
1293
1294 /* ****************************************************************
1295  *                                      parsenodes.h copy functions
1296  * ****************************************************************
1297  */
1298
1299 static RangeTblEntry *
1300 _copyRangeTblEntry(RangeTblEntry *from)
1301 {
1302         RangeTblEntry *newnode = makeNode(RangeTblEntry);
1303
1304         COPY_SCALAR_FIELD(rtekind);
1305         COPY_SCALAR_FIELD(relid);
1306         COPY_NODE_FIELD(subquery);
1307         COPY_NODE_FIELD(funcexpr);
1308         COPY_NODE_FIELD(coldeflist);
1309         COPY_SCALAR_FIELD(jointype);
1310         COPY_NODE_FIELD(joinaliasvars);
1311         COPY_NODE_FIELD(alias);
1312         COPY_NODE_FIELD(eref);
1313         COPY_SCALAR_FIELD(inh);
1314         COPY_SCALAR_FIELD(inFromCl);
1315         COPY_SCALAR_FIELD(requiredPerms);
1316         COPY_SCALAR_FIELD(checkAsUser);
1317
1318         return newnode;
1319 }
1320
1321 static FkConstraint *
1322 _copyFkConstraint(FkConstraint *from)
1323 {
1324         FkConstraint *newnode = makeNode(FkConstraint);
1325
1326         COPY_STRING_FIELD(constr_name);
1327         COPY_NODE_FIELD(pktable);
1328         COPY_NODE_FIELD(fk_attrs);
1329         COPY_NODE_FIELD(pk_attrs);
1330         COPY_SCALAR_FIELD(fk_matchtype);
1331         COPY_SCALAR_FIELD(fk_upd_action);
1332         COPY_SCALAR_FIELD(fk_del_action);
1333         COPY_SCALAR_FIELD(deferrable);
1334         COPY_SCALAR_FIELD(initdeferred);
1335         COPY_SCALAR_FIELD(skip_validation);
1336
1337         return newnode;
1338 }
1339
1340 static SortClause *
1341 _copySortClause(SortClause *from)
1342 {
1343         SortClause *newnode = makeNode(SortClause);
1344
1345         COPY_SCALAR_FIELD(tleSortGroupRef);
1346         COPY_SCALAR_FIELD(sortop);
1347
1348         return newnode;
1349 }
1350
1351 static GroupClause *
1352 _copyGroupClause(GroupClause *from)
1353 {
1354         GroupClause *newnode = makeNode(GroupClause);
1355
1356         COPY_SCALAR_FIELD(tleSortGroupRef);
1357         COPY_SCALAR_FIELD(sortop);
1358
1359         return newnode;
1360 }
1361
1362 static A_Expr *
1363 _copyAExpr(A_Expr *from)
1364 {
1365         A_Expr     *newnode = makeNode(A_Expr);
1366
1367         COPY_SCALAR_FIELD(kind);
1368         COPY_NODE_FIELD(name);
1369         COPY_NODE_FIELD(lexpr);
1370         COPY_NODE_FIELD(rexpr);
1371
1372         return newnode;
1373 }
1374
1375 static ColumnRef *
1376 _copyColumnRef(ColumnRef *from)
1377 {
1378         ColumnRef  *newnode = makeNode(ColumnRef);
1379
1380         COPY_NODE_FIELD(fields);
1381
1382         return newnode;
1383 }
1384
1385 static ParamRef *
1386 _copyParamRef(ParamRef *from)
1387 {
1388         ParamRef   *newnode = makeNode(ParamRef);
1389
1390         COPY_SCALAR_FIELD(number);
1391
1392         return newnode;
1393 }
1394
1395 static A_Const *
1396 _copyAConst(A_Const *from)
1397 {
1398         A_Const    *newnode = makeNode(A_Const);
1399
1400         /* This part must duplicate _copyValue */
1401         COPY_SCALAR_FIELD(val.type);
1402         switch (from->val.type)
1403         {
1404                 case T_Integer:
1405                         COPY_SCALAR_FIELD(val.val.ival);
1406                         break;
1407                 case T_Float:
1408                 case T_String:
1409                 case T_BitString:
1410                         COPY_STRING_FIELD(val.val.str);
1411                         break;
1412                 case T_Null:
1413                         /* nothing to do */
1414                         break;
1415                 default:
1416                         elog(ERROR, "unrecognized node type: %d",
1417                                  (int) from->val.type);
1418                         break;
1419         }
1420
1421         COPY_NODE_FIELD(typename);
1422
1423         return newnode;
1424 }
1425
1426 static FuncCall *
1427 _copyFuncCall(FuncCall *from)
1428 {
1429         FuncCall   *newnode = makeNode(FuncCall);
1430
1431         COPY_NODE_FIELD(funcname);
1432         COPY_NODE_FIELD(args);
1433         COPY_SCALAR_FIELD(agg_star);
1434         COPY_SCALAR_FIELD(agg_distinct);
1435
1436         return newnode;
1437 }
1438
1439 static A_Indices *
1440 _copyAIndices(A_Indices *from)
1441 {
1442         A_Indices  *newnode = makeNode(A_Indices);
1443
1444         COPY_NODE_FIELD(lidx);
1445         COPY_NODE_FIELD(uidx);
1446
1447         return newnode;
1448 }
1449
1450 static A_Indirection *
1451 _copyA_Indirection(A_Indirection *from)
1452 {
1453         A_Indirection *newnode = makeNode(A_Indirection);
1454
1455         COPY_NODE_FIELD(arg);
1456         COPY_NODE_FIELD(indirection);
1457
1458         return newnode;
1459 }
1460
1461 static ResTarget *
1462 _copyResTarget(ResTarget *from)
1463 {
1464         ResTarget  *newnode = makeNode(ResTarget);
1465
1466         COPY_STRING_FIELD(name);
1467         COPY_NODE_FIELD(indirection);
1468         COPY_NODE_FIELD(val);
1469
1470         return newnode;
1471 }
1472
1473 static TypeName *
1474 _copyTypeName(TypeName *from)
1475 {
1476         TypeName   *newnode = makeNode(TypeName);
1477
1478         COPY_NODE_FIELD(names);
1479         COPY_SCALAR_FIELD(typeid);
1480         COPY_SCALAR_FIELD(timezone);
1481         COPY_SCALAR_FIELD(setof);
1482         COPY_SCALAR_FIELD(pct_type);
1483         COPY_SCALAR_FIELD(typmod);
1484         COPY_NODE_FIELD(arrayBounds);
1485
1486         return newnode;
1487 }
1488
1489 static SortBy *
1490 _copySortBy(SortBy *from)
1491 {
1492         SortBy     *newnode = makeNode(SortBy);
1493
1494         COPY_SCALAR_FIELD(sortby_kind);
1495         COPY_NODE_FIELD(useOp);
1496         COPY_NODE_FIELD(node);
1497
1498         return newnode;
1499 }
1500
1501 static RangeSubselect *
1502 _copyRangeSubselect(RangeSubselect *from)
1503 {
1504         RangeSubselect *newnode = makeNode(RangeSubselect);
1505
1506         COPY_NODE_FIELD(subquery);
1507         COPY_NODE_FIELD(alias);
1508
1509         return newnode;
1510 }
1511
1512 static RangeFunction *
1513 _copyRangeFunction(RangeFunction *from)
1514 {
1515         RangeFunction *newnode = makeNode(RangeFunction);
1516
1517         COPY_NODE_FIELD(funccallnode);
1518         COPY_NODE_FIELD(alias);
1519         COPY_NODE_FIELD(coldeflist);
1520
1521         return newnode;
1522 }
1523
1524 static TypeCast *
1525 _copyTypeCast(TypeCast *from)
1526 {
1527         TypeCast   *newnode = makeNode(TypeCast);
1528
1529         COPY_NODE_FIELD(arg);
1530         COPY_NODE_FIELD(typename);
1531
1532         return newnode;
1533 }
1534
1535 static IndexElem *
1536 _copyIndexElem(IndexElem *from)
1537 {
1538         IndexElem  *newnode = makeNode(IndexElem);
1539
1540         COPY_STRING_FIELD(name);
1541         COPY_NODE_FIELD(expr);
1542         COPY_NODE_FIELD(opclass);
1543
1544         return newnode;
1545 }
1546
1547 static ColumnDef *
1548 _copyColumnDef(ColumnDef *from)
1549 {
1550         ColumnDef  *newnode = makeNode(ColumnDef);
1551
1552         COPY_STRING_FIELD(colname);
1553         COPY_NODE_FIELD(typename);
1554         COPY_SCALAR_FIELD(inhcount);
1555         COPY_SCALAR_FIELD(is_local);
1556         COPY_SCALAR_FIELD(is_not_null);
1557         COPY_NODE_FIELD(raw_default);
1558         COPY_STRING_FIELD(cooked_default);
1559         COPY_NODE_FIELD(constraints);
1560         COPY_NODE_FIELD(support);
1561
1562         return newnode;
1563 }
1564
1565 static Constraint *
1566 _copyConstraint(Constraint *from)
1567 {
1568         Constraint *newnode = makeNode(Constraint);
1569
1570         COPY_SCALAR_FIELD(contype);
1571         COPY_STRING_FIELD(name);
1572         COPY_NODE_FIELD(raw_expr);
1573         COPY_STRING_FIELD(cooked_expr);
1574         COPY_NODE_FIELD(keys);
1575         COPY_STRING_FIELD(indexspace);
1576
1577         return newnode;
1578 }
1579
1580 static DefElem *
1581 _copyDefElem(DefElem *from)
1582 {
1583         DefElem    *newnode = makeNode(DefElem);
1584
1585         COPY_STRING_FIELD(defname);
1586         COPY_NODE_FIELD(arg);
1587
1588         return newnode;
1589 }
1590
1591 static Query *
1592 _copyQuery(Query *from)
1593 {
1594         Query      *newnode = makeNode(Query);
1595
1596         COPY_SCALAR_FIELD(commandType);
1597         COPY_SCALAR_FIELD(querySource);
1598         COPY_SCALAR_FIELD(canSetTag);
1599         COPY_NODE_FIELD(utilityStmt);
1600         COPY_SCALAR_FIELD(resultRelation);
1601         COPY_NODE_FIELD(into);
1602         COPY_SCALAR_FIELD(intoHasOids);
1603         COPY_SCALAR_FIELD(hasAggs);
1604         COPY_SCALAR_FIELD(hasSubLinks);
1605         COPY_NODE_FIELD(rtable);
1606         COPY_NODE_FIELD(jointree);
1607         COPY_NODE_FIELD(rowMarks);
1608         COPY_SCALAR_FIELD(forUpdate);
1609         COPY_NODE_FIELD(targetList);
1610         COPY_NODE_FIELD(groupClause);
1611         COPY_NODE_FIELD(havingQual);
1612         COPY_NODE_FIELD(distinctClause);
1613         COPY_NODE_FIELD(sortClause);
1614         COPY_NODE_FIELD(limitOffset);
1615         COPY_NODE_FIELD(limitCount);
1616         COPY_NODE_FIELD(setOperations);
1617         COPY_NODE_FIELD(resultRelations);
1618
1619         return newnode;
1620 }
1621
1622 static InsertStmt *
1623 _copyInsertStmt(InsertStmt *from)
1624 {
1625         InsertStmt *newnode = makeNode(InsertStmt);
1626
1627         COPY_NODE_FIELD(relation);
1628         COPY_NODE_FIELD(cols);
1629         COPY_NODE_FIELD(targetList);
1630         COPY_NODE_FIELD(selectStmt);
1631
1632         return newnode;
1633 }
1634
1635 static DeleteStmt *
1636 _copyDeleteStmt(DeleteStmt *from)
1637 {
1638         DeleteStmt *newnode = makeNode(DeleteStmt);
1639
1640         COPY_NODE_FIELD(relation);
1641         COPY_NODE_FIELD(whereClause);
1642         COPY_NODE_FIELD(usingClause);
1643
1644         return newnode;
1645 }
1646
1647 static UpdateStmt *
1648 _copyUpdateStmt(UpdateStmt *from)
1649 {
1650         UpdateStmt *newnode = makeNode(UpdateStmt);
1651
1652         COPY_NODE_FIELD(relation);
1653         COPY_NODE_FIELD(targetList);
1654         COPY_NODE_FIELD(whereClause);
1655         COPY_NODE_FIELD(fromClause);
1656
1657         return newnode;
1658 }
1659
1660 static SelectStmt *
1661 _copySelectStmt(SelectStmt *from)
1662 {
1663         SelectStmt *newnode = makeNode(SelectStmt);
1664
1665         COPY_NODE_FIELD(distinctClause);
1666         COPY_NODE_FIELD(into);
1667         COPY_NODE_FIELD(intoColNames);
1668         COPY_SCALAR_FIELD(intoHasOids);
1669         COPY_NODE_FIELD(targetList);
1670         COPY_NODE_FIELD(fromClause);
1671         COPY_NODE_FIELD(whereClause);
1672         COPY_NODE_FIELD(groupClause);
1673         COPY_NODE_FIELD(havingClause);
1674         COPY_NODE_FIELD(sortClause);
1675         COPY_NODE_FIELD(limitOffset);
1676         COPY_NODE_FIELD(limitCount);
1677         COPY_NODE_FIELD(lockedRels);
1678         COPY_SCALAR_FIELD(forUpdate);
1679         COPY_SCALAR_FIELD(op);
1680         COPY_SCALAR_FIELD(all);
1681         COPY_NODE_FIELD(larg);
1682         COPY_NODE_FIELD(rarg);
1683
1684         return newnode;
1685 }
1686
1687 static SetOperationStmt *
1688 _copySetOperationStmt(SetOperationStmt *from)
1689 {
1690         SetOperationStmt *newnode = makeNode(SetOperationStmt);
1691
1692         COPY_SCALAR_FIELD(op);
1693         COPY_SCALAR_FIELD(all);
1694         COPY_NODE_FIELD(larg);
1695         COPY_NODE_FIELD(rarg);
1696         COPY_NODE_FIELD(colTypes);
1697
1698         return newnode;
1699 }
1700
1701 static AlterTableStmt *
1702 _copyAlterTableStmt(AlterTableStmt *from)
1703 {
1704         AlterTableStmt *newnode = makeNode(AlterTableStmt);
1705
1706         COPY_NODE_FIELD(relation);
1707         COPY_NODE_FIELD(cmds);
1708         COPY_SCALAR_FIELD(relkind);
1709
1710         return newnode;
1711 }
1712
1713 static AlterTableCmd *
1714 _copyAlterTableCmd(AlterTableCmd *from)
1715 {
1716         AlterTableCmd *newnode = makeNode(AlterTableCmd);
1717
1718         COPY_SCALAR_FIELD(subtype);
1719         COPY_STRING_FIELD(name);
1720         COPY_NODE_FIELD(def);
1721         COPY_NODE_FIELD(transform);
1722         COPY_SCALAR_FIELD(behavior);
1723
1724         return newnode;
1725 }
1726
1727 static AlterDomainStmt *
1728 _copyAlterDomainStmt(AlterDomainStmt *from)
1729 {
1730         AlterDomainStmt *newnode = makeNode(AlterDomainStmt);
1731
1732         COPY_SCALAR_FIELD(subtype);
1733         COPY_NODE_FIELD(typename);
1734         COPY_STRING_FIELD(name);
1735         COPY_NODE_FIELD(def);
1736         COPY_SCALAR_FIELD(behavior);
1737
1738         return newnode;
1739 }
1740
1741 static GrantStmt *
1742 _copyGrantStmt(GrantStmt *from)
1743 {
1744         GrantStmt  *newnode = makeNode(GrantStmt);
1745
1746         COPY_SCALAR_FIELD(is_grant);
1747         COPY_SCALAR_FIELD(objtype);
1748         COPY_NODE_FIELD(objects);
1749         COPY_NODE_FIELD(privileges);
1750         COPY_NODE_FIELD(grantees);
1751         COPY_SCALAR_FIELD(grant_option);
1752         COPY_SCALAR_FIELD(behavior);
1753
1754         return newnode;
1755 }
1756
1757 static PrivGrantee *
1758 _copyPrivGrantee(PrivGrantee *from)
1759 {
1760         PrivGrantee *newnode = makeNode(PrivGrantee);
1761
1762         COPY_STRING_FIELD(username);
1763         COPY_STRING_FIELD(groupname);
1764
1765         return newnode;
1766 }
1767
1768 static FuncWithArgs *
1769 _copyFuncWithArgs(FuncWithArgs *from)
1770 {
1771         FuncWithArgs *newnode = makeNode(FuncWithArgs);
1772
1773         COPY_NODE_FIELD(funcname);
1774         COPY_NODE_FIELD(funcargs);
1775
1776         return newnode;
1777 }
1778
1779 static DeclareCursorStmt *
1780 _copyDeclareCursorStmt(DeclareCursorStmt *from)
1781 {
1782         DeclareCursorStmt *newnode = makeNode(DeclareCursorStmt);
1783
1784         COPY_STRING_FIELD(portalname);
1785         COPY_SCALAR_FIELD(options);
1786         COPY_NODE_FIELD(query);
1787
1788         return newnode;
1789 }
1790
1791 static ClosePortalStmt *
1792 _copyClosePortalStmt(ClosePortalStmt *from)
1793 {
1794         ClosePortalStmt *newnode = makeNode(ClosePortalStmt);
1795
1796         COPY_STRING_FIELD(portalname);
1797
1798         return newnode;
1799 }
1800
1801 static ClusterStmt *
1802 _copyClusterStmt(ClusterStmt *from)
1803 {
1804         ClusterStmt *newnode = makeNode(ClusterStmt);
1805
1806         COPY_NODE_FIELD(relation);
1807         COPY_STRING_FIELD(indexname);
1808
1809         return newnode;
1810 }
1811
1812 static CopyStmt *
1813 _copyCopyStmt(CopyStmt *from)
1814 {
1815         CopyStmt   *newnode = makeNode(CopyStmt);
1816
1817         COPY_NODE_FIELD(relation);
1818         COPY_NODE_FIELD(attlist);
1819         COPY_SCALAR_FIELD(is_from);
1820         COPY_STRING_FIELD(filename);
1821         COPY_NODE_FIELD(options);
1822
1823         return newnode;
1824 }
1825
1826 static CreateStmt *
1827 _copyCreateStmt(CreateStmt *from)
1828 {
1829         CreateStmt *newnode = makeNode(CreateStmt);
1830
1831         COPY_NODE_FIELD(relation);
1832         COPY_NODE_FIELD(tableElts);
1833         COPY_NODE_FIELD(inhRelations);
1834         COPY_NODE_FIELD(constraints);
1835         COPY_SCALAR_FIELD(hasoids);
1836         COPY_SCALAR_FIELD(oncommit);
1837         COPY_STRING_FIELD(tablespacename);
1838
1839         return newnode;
1840 }
1841
1842 static InhRelation *
1843 _copyInhRelation(InhRelation *from)
1844 {
1845         InhRelation *newnode = makeNode(InhRelation);
1846
1847         COPY_NODE_FIELD(relation);
1848         COPY_SCALAR_FIELD(including_defaults);
1849
1850         return newnode;
1851 }
1852
1853 static DefineStmt *
1854 _copyDefineStmt(DefineStmt *from)
1855 {
1856         DefineStmt *newnode = makeNode(DefineStmt);
1857
1858         COPY_SCALAR_FIELD(kind);
1859         COPY_NODE_FIELD(defnames);
1860         COPY_NODE_FIELD(definition);
1861
1862         return newnode;
1863 }
1864
1865 static DropStmt *
1866 _copyDropStmt(DropStmt *from)
1867 {
1868         DropStmt   *newnode = makeNode(DropStmt);
1869
1870         COPY_NODE_FIELD(objects);
1871         COPY_SCALAR_FIELD(removeType);
1872         COPY_SCALAR_FIELD(behavior);
1873
1874         return newnode;
1875 }
1876
1877 static TruncateStmt *
1878 _copyTruncateStmt(TruncateStmt *from)
1879 {
1880         TruncateStmt *newnode = makeNode(TruncateStmt);
1881
1882         COPY_NODE_FIELD(relations);
1883
1884         return newnode;
1885 }
1886
1887 static CommentStmt *
1888 _copyCommentStmt(CommentStmt *from)
1889 {
1890         CommentStmt *newnode = makeNode(CommentStmt);
1891
1892         COPY_SCALAR_FIELD(objtype);
1893         COPY_NODE_FIELD(objname);
1894         COPY_NODE_FIELD(objargs);
1895         COPY_STRING_FIELD(comment);
1896
1897         return newnode;
1898 }
1899
1900 static FetchStmt *
1901 _copyFetchStmt(FetchStmt *from)
1902 {
1903         FetchStmt  *newnode = makeNode(FetchStmt);
1904
1905         COPY_SCALAR_FIELD(direction);
1906         COPY_SCALAR_FIELD(howMany);
1907         COPY_STRING_FIELD(portalname);
1908         COPY_SCALAR_FIELD(ismove);
1909
1910         return newnode;
1911 }
1912
1913 static IndexStmt *
1914 _copyIndexStmt(IndexStmt *from)
1915 {
1916         IndexStmt  *newnode = makeNode(IndexStmt);
1917
1918         COPY_STRING_FIELD(idxname);
1919         COPY_NODE_FIELD(relation);
1920         COPY_STRING_FIELD(accessMethod);
1921         COPY_STRING_FIELD(tableSpace);
1922         COPY_NODE_FIELD(indexParams);
1923         COPY_NODE_FIELD(whereClause);
1924         COPY_NODE_FIELD(rangetable);
1925         COPY_SCALAR_FIELD(unique);
1926         COPY_SCALAR_FIELD(primary);
1927         COPY_SCALAR_FIELD(isconstraint);
1928
1929         return newnode;
1930 }
1931
1932 static CreateFunctionStmt *
1933 _copyCreateFunctionStmt(CreateFunctionStmt *from)
1934 {
1935         CreateFunctionStmt *newnode = makeNode(CreateFunctionStmt);
1936
1937         COPY_SCALAR_FIELD(replace);
1938         COPY_NODE_FIELD(funcname);
1939         COPY_NODE_FIELD(parameters);
1940         COPY_NODE_FIELD(returnType);
1941         COPY_NODE_FIELD(options);
1942         COPY_NODE_FIELD(withClause);
1943
1944         return newnode;
1945 }
1946
1947 static FunctionParameter *
1948 _copyFunctionParameter(FunctionParameter *from)
1949 {
1950         FunctionParameter *newnode = makeNode(FunctionParameter);
1951
1952         COPY_STRING_FIELD(name);
1953         COPY_NODE_FIELD(argType);
1954         COPY_SCALAR_FIELD(mode);
1955
1956         return newnode;
1957 }
1958
1959 static AlterFunctionStmt *
1960 _copyAlterFunctionStmt(AlterFunctionStmt *from)
1961 {
1962         AlterFunctionStmt *newnode = makeNode(AlterFunctionStmt);
1963
1964         COPY_NODE_FIELD(func);
1965         COPY_NODE_FIELD(actions);
1966
1967         return newnode;
1968 }
1969
1970 static RemoveAggrStmt *
1971 _copyRemoveAggrStmt(RemoveAggrStmt *from)
1972 {
1973         RemoveAggrStmt *newnode = makeNode(RemoveAggrStmt);
1974
1975         COPY_NODE_FIELD(aggname);
1976         COPY_NODE_FIELD(aggtype);
1977         COPY_SCALAR_FIELD(behavior);
1978
1979         return newnode;
1980 }
1981
1982 static RemoveFuncStmt *
1983 _copyRemoveFuncStmt(RemoveFuncStmt *from)
1984 {
1985         RemoveFuncStmt *newnode = makeNode(RemoveFuncStmt);
1986
1987         COPY_NODE_FIELD(funcname);
1988         COPY_NODE_FIELD(args);
1989         COPY_SCALAR_FIELD(behavior);
1990
1991         return newnode;
1992 }
1993
1994 static RemoveOperStmt *
1995 _copyRemoveOperStmt(RemoveOperStmt *from)
1996 {
1997         RemoveOperStmt *newnode = makeNode(RemoveOperStmt);
1998
1999         COPY_NODE_FIELD(opname);
2000         COPY_NODE_FIELD(args);
2001         COPY_SCALAR_FIELD(behavior);
2002
2003         return newnode;
2004 }
2005
2006 static RemoveOpClassStmt *
2007 _copyRemoveOpClassStmt(RemoveOpClassStmt *from)
2008 {
2009         RemoveOpClassStmt *newnode = makeNode(RemoveOpClassStmt);
2010
2011         COPY_NODE_FIELD(opclassname);
2012         COPY_STRING_FIELD(amname);
2013         COPY_SCALAR_FIELD(behavior);
2014
2015         return newnode;
2016 }
2017
2018 static RenameStmt *
2019 _copyRenameStmt(RenameStmt *from)
2020 {
2021         RenameStmt *newnode = makeNode(RenameStmt);
2022
2023         COPY_NODE_FIELD(relation);
2024         COPY_NODE_FIELD(object);
2025         COPY_NODE_FIELD(objarg);
2026         COPY_STRING_FIELD(subname);
2027         COPY_STRING_FIELD(newname);
2028         COPY_SCALAR_FIELD(renameType);
2029
2030         return newnode;
2031 }
2032
2033 static AlterOwnerStmt *
2034 _copyAlterOwnerStmt(AlterOwnerStmt *from)
2035 {
2036         AlterOwnerStmt *newnode = makeNode(AlterOwnerStmt);
2037
2038         COPY_NODE_FIELD(relation);
2039         COPY_NODE_FIELD(object);
2040         COPY_NODE_FIELD(objarg);
2041         COPY_STRING_FIELD(addname);
2042         COPY_STRING_FIELD(newowner);
2043         COPY_SCALAR_FIELD(objectType);
2044
2045         return newnode;
2046 }
2047
2048 static RuleStmt *
2049 _copyRuleStmt(RuleStmt *from)
2050 {
2051         RuleStmt   *newnode = makeNode(RuleStmt);
2052
2053         COPY_NODE_FIELD(relation);
2054         COPY_STRING_FIELD(rulename);
2055         COPY_NODE_FIELD(whereClause);
2056         COPY_SCALAR_FIELD(event);
2057         COPY_SCALAR_FIELD(instead);
2058         COPY_NODE_FIELD(actions);
2059         COPY_SCALAR_FIELD(replace);
2060
2061         return newnode;
2062 }
2063
2064 static NotifyStmt *
2065 _copyNotifyStmt(NotifyStmt *from)
2066 {
2067         NotifyStmt *newnode = makeNode(NotifyStmt);
2068
2069         COPY_NODE_FIELD(relation);
2070
2071         return newnode;
2072 }
2073
2074 static ListenStmt *
2075 _copyListenStmt(ListenStmt *from)
2076 {
2077         ListenStmt *newnode = makeNode(ListenStmt);
2078
2079         COPY_NODE_FIELD(relation);
2080
2081         return newnode;
2082 }
2083
2084 static UnlistenStmt *
2085 _copyUnlistenStmt(UnlistenStmt *from)
2086 {
2087         UnlistenStmt *newnode = makeNode(UnlistenStmt);
2088
2089         COPY_NODE_FIELD(relation);
2090
2091         return newnode;
2092 }
2093
2094 static TransactionStmt *
2095 _copyTransactionStmt(TransactionStmt *from)
2096 {
2097         TransactionStmt *newnode = makeNode(TransactionStmt);
2098
2099         COPY_SCALAR_FIELD(kind);
2100         COPY_NODE_FIELD(options);
2101
2102         return newnode;
2103 }
2104
2105 static CompositeTypeStmt *
2106 _copyCompositeTypeStmt(CompositeTypeStmt *from)
2107 {
2108         CompositeTypeStmt *newnode = makeNode(CompositeTypeStmt);
2109
2110         COPY_NODE_FIELD(typevar);
2111         COPY_NODE_FIELD(coldeflist);
2112
2113         return newnode;
2114 }
2115
2116 static ViewStmt *
2117 _copyViewStmt(ViewStmt *from)
2118 {
2119         ViewStmt   *newnode = makeNode(ViewStmt);
2120
2121         COPY_NODE_FIELD(view);
2122         COPY_NODE_FIELD(aliases);
2123         COPY_NODE_FIELD(query);
2124         COPY_SCALAR_FIELD(replace);
2125
2126         return newnode;
2127 }
2128
2129 static LoadStmt *
2130 _copyLoadStmt(LoadStmt *from)
2131 {
2132         LoadStmt   *newnode = makeNode(LoadStmt);
2133
2134         COPY_STRING_FIELD(filename);
2135
2136         return newnode;
2137 }
2138
2139 static CreateDomainStmt *
2140 _copyCreateDomainStmt(CreateDomainStmt *from)
2141 {
2142         CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
2143
2144         COPY_NODE_FIELD(domainname);
2145         COPY_NODE_FIELD(typename);
2146         COPY_NODE_FIELD(constraints);
2147
2148         return newnode;
2149 }
2150
2151 static CreateOpClassStmt *
2152 _copyCreateOpClassStmt(CreateOpClassStmt *from)
2153 {
2154         CreateOpClassStmt *newnode = makeNode(CreateOpClassStmt);
2155
2156         COPY_NODE_FIELD(opclassname);
2157         COPY_STRING_FIELD(amname);
2158         COPY_NODE_FIELD(datatype);
2159         COPY_NODE_FIELD(items);
2160         COPY_SCALAR_FIELD(isDefault);
2161
2162         return newnode;
2163 }
2164
2165 static CreateOpClassItem *
2166 _copyCreateOpClassItem(CreateOpClassItem *from)
2167 {
2168         CreateOpClassItem *newnode = makeNode(CreateOpClassItem);
2169
2170         COPY_SCALAR_FIELD(itemtype);
2171         COPY_NODE_FIELD(name);
2172         COPY_NODE_FIELD(args);
2173         COPY_SCALAR_FIELD(number);
2174         COPY_SCALAR_FIELD(recheck);
2175         COPY_NODE_FIELD(storedtype);
2176
2177         return newnode;
2178 }
2179
2180 static CreatedbStmt *
2181 _copyCreatedbStmt(CreatedbStmt *from)
2182 {
2183         CreatedbStmt *newnode = makeNode(CreatedbStmt);
2184
2185         COPY_STRING_FIELD(dbname);
2186         COPY_NODE_FIELD(options);
2187
2188         return newnode;
2189 }
2190
2191 static AlterDatabaseSetStmt *
2192 _copyAlterDatabaseSetStmt(AlterDatabaseSetStmt *from)
2193 {
2194         AlterDatabaseSetStmt *newnode = makeNode(AlterDatabaseSetStmt);
2195
2196         COPY_STRING_FIELD(dbname);
2197         COPY_STRING_FIELD(variable);
2198         COPY_NODE_FIELD(value);
2199
2200         return newnode;
2201 }
2202
2203 static DropdbStmt *
2204 _copyDropdbStmt(DropdbStmt *from)
2205 {
2206         DropdbStmt *newnode = makeNode(DropdbStmt);
2207
2208         COPY_STRING_FIELD(dbname);
2209
2210         return newnode;
2211 }
2212
2213 static VacuumStmt *
2214 _copyVacuumStmt(VacuumStmt *from)
2215 {
2216         VacuumStmt *newnode = makeNode(VacuumStmt);
2217
2218         COPY_SCALAR_FIELD(vacuum);
2219         COPY_SCALAR_FIELD(full);
2220         COPY_SCALAR_FIELD(analyze);
2221         COPY_SCALAR_FIELD(freeze);
2222         COPY_SCALAR_FIELD(verbose);
2223         COPY_NODE_FIELD(relation);
2224         COPY_NODE_FIELD(va_cols);
2225
2226         return newnode;
2227 }
2228
2229 static ExplainStmt *
2230 _copyExplainStmt(ExplainStmt *from)
2231 {
2232         ExplainStmt *newnode = makeNode(ExplainStmt);
2233
2234         COPY_NODE_FIELD(query);
2235         COPY_SCALAR_FIELD(verbose);
2236         COPY_SCALAR_FIELD(analyze);
2237
2238         return newnode;
2239 }
2240
2241 static CreateSeqStmt *
2242 _copyCreateSeqStmt(CreateSeqStmt *from)
2243 {
2244         CreateSeqStmt *newnode = makeNode(CreateSeqStmt);
2245
2246         COPY_NODE_FIELD(sequence);
2247         COPY_NODE_FIELD(options);
2248
2249         return newnode;
2250 }
2251
2252 static AlterSeqStmt *
2253 _copyAlterSeqStmt(AlterSeqStmt *from)
2254 {
2255         AlterSeqStmt *newnode = makeNode(AlterSeqStmt);
2256
2257         COPY_NODE_FIELD(sequence);
2258         COPY_NODE_FIELD(options);
2259
2260         return newnode;
2261 }
2262
2263 static VariableSetStmt *
2264 _copyVariableSetStmt(VariableSetStmt *from)
2265 {
2266         VariableSetStmt *newnode = makeNode(VariableSetStmt);
2267
2268         COPY_STRING_FIELD(name);
2269         COPY_NODE_FIELD(args);
2270         COPY_SCALAR_FIELD(is_local);
2271
2272         return newnode;
2273 }
2274
2275 static VariableShowStmt *
2276 _copyVariableShowStmt(VariableShowStmt *from)
2277 {
2278         VariableShowStmt *newnode = makeNode(VariableShowStmt);
2279
2280         COPY_STRING_FIELD(name);
2281
2282         return newnode;
2283 }
2284
2285 static VariableResetStmt *
2286 _copyVariableResetStmt(VariableResetStmt *from)
2287 {
2288         VariableResetStmt *newnode = makeNode(VariableResetStmt);
2289
2290         COPY_STRING_FIELD(name);
2291
2292         return newnode;
2293 }
2294
2295 static CreateTableSpaceStmt *
2296 _copyCreateTableSpaceStmt(CreateTableSpaceStmt *from)
2297 {
2298         CreateTableSpaceStmt *newnode = makeNode(CreateTableSpaceStmt);
2299
2300         COPY_STRING_FIELD(tablespacename);
2301         COPY_STRING_FIELD(owner);
2302         COPY_STRING_FIELD(location);
2303
2304         return newnode;
2305 }
2306
2307 static DropTableSpaceStmt *
2308 _copyDropTableSpaceStmt(DropTableSpaceStmt *from)
2309 {
2310         DropTableSpaceStmt *newnode = makeNode(DropTableSpaceStmt);
2311
2312         COPY_STRING_FIELD(tablespacename);
2313
2314         return newnode;
2315 }
2316
2317 static CreateTrigStmt *
2318 _copyCreateTrigStmt(CreateTrigStmt *from)
2319 {
2320         CreateTrigStmt *newnode = makeNode(CreateTrigStmt);
2321
2322         COPY_STRING_FIELD(trigname);
2323         COPY_NODE_FIELD(relation);
2324         COPY_NODE_FIELD(funcname);
2325         COPY_NODE_FIELD(args);
2326         COPY_SCALAR_FIELD(before);
2327         COPY_SCALAR_FIELD(row);
2328         strcpy(newnode->actions, from->actions);        /* in-line string field */
2329         COPY_SCALAR_FIELD(isconstraint);
2330         COPY_SCALAR_FIELD(deferrable);
2331         COPY_SCALAR_FIELD(initdeferred);
2332         COPY_NODE_FIELD(constrrel);
2333
2334         return newnode;
2335 }
2336
2337 static DropPropertyStmt *
2338 _copyDropPropertyStmt(DropPropertyStmt *from)
2339 {
2340         DropPropertyStmt *newnode = makeNode(DropPropertyStmt);
2341
2342         COPY_NODE_FIELD(relation);
2343         COPY_STRING_FIELD(property);
2344         COPY_SCALAR_FIELD(removeType);
2345         COPY_SCALAR_FIELD(behavior);
2346
2347         return newnode;
2348 }
2349
2350 static CreatePLangStmt *
2351 _copyCreatePLangStmt(CreatePLangStmt *from)
2352 {
2353         CreatePLangStmt *newnode = makeNode(CreatePLangStmt);
2354
2355         COPY_STRING_FIELD(plname);
2356         COPY_NODE_FIELD(plhandler);
2357         COPY_NODE_FIELD(plvalidator);
2358         COPY_SCALAR_FIELD(pltrusted);
2359
2360         return newnode;
2361 }
2362
2363 static DropPLangStmt *
2364 _copyDropPLangStmt(DropPLangStmt *from)
2365 {
2366         DropPLangStmt *newnode = makeNode(DropPLangStmt);
2367
2368         COPY_STRING_FIELD(plname);
2369         COPY_SCALAR_FIELD(behavior);
2370
2371         return newnode;
2372 }
2373
2374 static CreateUserStmt *
2375 _copyCreateUserStmt(CreateUserStmt *from)
2376 {
2377         CreateUserStmt *newnode = makeNode(CreateUserStmt);
2378
2379         COPY_STRING_FIELD(user);
2380         COPY_NODE_FIELD(options);
2381
2382         return newnode;
2383 }
2384
2385 static AlterUserStmt *
2386 _copyAlterUserStmt(AlterUserStmt *from)
2387 {
2388         AlterUserStmt *newnode = makeNode(AlterUserStmt);
2389
2390         COPY_STRING_FIELD(user);
2391         COPY_NODE_FIELD(options);
2392
2393         return newnode;
2394 }
2395
2396 static AlterUserSetStmt *
2397 _copyAlterUserSetStmt(AlterUserSetStmt *from)
2398 {
2399         AlterUserSetStmt *newnode = makeNode(AlterUserSetStmt);
2400
2401         COPY_STRING_FIELD(user);
2402         COPY_STRING_FIELD(variable);
2403         COPY_NODE_FIELD(value);
2404
2405         return newnode;
2406 }
2407
2408 static DropUserStmt *
2409 _copyDropUserStmt(DropUserStmt *from)
2410 {
2411         DropUserStmt *newnode = makeNode(DropUserStmt);
2412
2413         COPY_NODE_FIELD(users);
2414
2415         return newnode;
2416 }
2417
2418 static LockStmt *
2419 _copyLockStmt(LockStmt *from)
2420 {
2421         LockStmt   *newnode = makeNode(LockStmt);
2422
2423         COPY_NODE_FIELD(relations);
2424         COPY_SCALAR_FIELD(mode);
2425         COPY_SCALAR_FIELD(nowait);
2426
2427         return newnode;
2428 }
2429
2430 static ConstraintsSetStmt *
2431 _copyConstraintsSetStmt(ConstraintsSetStmt *from)
2432 {
2433         ConstraintsSetStmt *newnode = makeNode(ConstraintsSetStmt);
2434
2435         COPY_NODE_FIELD(constraints);
2436         COPY_SCALAR_FIELD(deferred);
2437
2438         return newnode;
2439 }
2440
2441 static CreateGroupStmt *
2442 _copyCreateGroupStmt(CreateGroupStmt *from)
2443 {
2444         CreateGroupStmt *newnode = makeNode(CreateGroupStmt);
2445
2446         COPY_STRING_FIELD(name);
2447         COPY_NODE_FIELD(options);
2448
2449         return newnode;
2450 }
2451
2452 static AlterGroupStmt *
2453 _copyAlterGroupStmt(AlterGroupStmt *from)
2454 {
2455         AlterGroupStmt *newnode = makeNode(AlterGroupStmt);
2456
2457         COPY_STRING_FIELD(name);
2458         COPY_SCALAR_FIELD(action);
2459         COPY_NODE_FIELD(listUsers);
2460
2461         return newnode;
2462 }
2463
2464 static DropGroupStmt *
2465 _copyDropGroupStmt(DropGroupStmt *from)
2466 {
2467         DropGroupStmt *newnode = makeNode(DropGroupStmt);
2468
2469         COPY_STRING_FIELD(name);
2470
2471         return newnode;
2472 }
2473
2474 static ReindexStmt *
2475 _copyReindexStmt(ReindexStmt *from)
2476 {
2477         ReindexStmt *newnode = makeNode(ReindexStmt);
2478
2479         COPY_SCALAR_FIELD(kind);
2480         COPY_NODE_FIELD(relation);
2481         COPY_STRING_FIELD(name);
2482         COPY_SCALAR_FIELD(force);
2483         COPY_SCALAR_FIELD(all);
2484
2485         return newnode;
2486 }
2487
2488 static CreateSchemaStmt *
2489 _copyCreateSchemaStmt(CreateSchemaStmt *from)
2490 {
2491         CreateSchemaStmt *newnode = makeNode(CreateSchemaStmt);
2492
2493         COPY_STRING_FIELD(schemaname);
2494         COPY_STRING_FIELD(authid);
2495         COPY_NODE_FIELD(schemaElts);
2496
2497         return newnode;
2498 }
2499
2500 static CreateConversionStmt *
2501 _copyCreateConversionStmt(CreateConversionStmt *from)
2502 {
2503         CreateConversionStmt *newnode = makeNode(CreateConversionStmt);
2504
2505         COPY_NODE_FIELD(conversion_name);
2506         COPY_STRING_FIELD(for_encoding_name);
2507         COPY_STRING_FIELD(to_encoding_name);
2508         COPY_NODE_FIELD(func_name);
2509         COPY_SCALAR_FIELD(def);
2510
2511         return newnode;
2512 }
2513
2514 static CreateCastStmt *
2515 _copyCreateCastStmt(CreateCastStmt *from)
2516 {
2517         CreateCastStmt *newnode = makeNode(CreateCastStmt);
2518
2519         COPY_NODE_FIELD(sourcetype);
2520         COPY_NODE_FIELD(targettype);
2521         COPY_NODE_FIELD(func);
2522         COPY_SCALAR_FIELD(context);
2523
2524         return newnode;
2525 }
2526
2527 static DropCastStmt *
2528 _copyDropCastStmt(DropCastStmt *from)
2529 {
2530         DropCastStmt *newnode = makeNode(DropCastStmt);
2531
2532         COPY_NODE_FIELD(sourcetype);
2533         COPY_NODE_FIELD(targettype);
2534         COPY_SCALAR_FIELD(behavior);
2535
2536         return newnode;
2537 }
2538
2539 static PrepareStmt *
2540 _copyPrepareStmt(PrepareStmt *from)
2541 {
2542         PrepareStmt *newnode = makeNode(PrepareStmt);
2543
2544         COPY_STRING_FIELD(name);
2545         COPY_NODE_FIELD(argtypes);
2546         COPY_NODE_FIELD(argtype_oids);
2547         COPY_NODE_FIELD(query);
2548
2549         return newnode;
2550 }
2551
2552 static ExecuteStmt *
2553 _copyExecuteStmt(ExecuteStmt *from)
2554 {
2555         ExecuteStmt *newnode = makeNode(ExecuteStmt);
2556
2557         COPY_STRING_FIELD(name);
2558         COPY_NODE_FIELD(into);
2559         COPY_NODE_FIELD(params);
2560
2561         return newnode;
2562 }
2563
2564 static DeallocateStmt *
2565 _copyDeallocateStmt(DeallocateStmt *from)
2566 {
2567         DeallocateStmt *newnode = makeNode(DeallocateStmt);
2568
2569         COPY_STRING_FIELD(name);
2570
2571         return newnode;
2572 }
2573
2574
2575 /* ****************************************************************
2576  *                                      pg_list.h copy functions
2577  * ****************************************************************
2578  */
2579
2580 /*
2581  * Perform a deep copy of the specified list, using copyObject(). The
2582  * list MUST be of type T_List; T_IntList and T_OidList nodes don't
2583  * need deep copies, so they should be copied via list_copy()
2584  */
2585 #define COPY_NODE_CELL(new, old)                                        \
2586         (new) = (ListCell *) palloc(sizeof(ListCell));  \
2587         lfirst(new) = copyObject(lfirst(old));
2588
2589 static List *
2590 _copyList(List *from)
2591 {
2592         List       *new;
2593         ListCell   *curr_old;
2594         ListCell   *prev_new;
2595
2596         Assert(list_length(from) >= 1);
2597
2598         new = makeNode(List);
2599         new->length = from->length;
2600
2601         COPY_NODE_CELL(new->head, from->head);
2602         prev_new = new->head;
2603         curr_old = lnext(from->head);
2604
2605         while (curr_old)
2606         {
2607                 COPY_NODE_CELL(prev_new->next, curr_old);
2608                 prev_new = prev_new->next;
2609                 curr_old = curr_old->next;
2610         }
2611         prev_new->next = NULL;
2612         new->tail = prev_new;
2613
2614         return new;
2615 }
2616
2617 /* ****************************************************************
2618  *                                      value.h copy functions
2619  * ****************************************************************
2620  */
2621 static Value *
2622 _copyValue(Value *from)
2623 {
2624         Value      *newnode = makeNode(Value);
2625
2626         /* See also _copyAConst when changing this code! */
2627
2628         COPY_SCALAR_FIELD(type);
2629         switch (from->type)
2630         {
2631                 case T_Integer:
2632                         COPY_SCALAR_FIELD(val.ival);
2633                         break;
2634                 case T_Float:
2635                 case T_String:
2636                 case T_BitString:
2637                         COPY_STRING_FIELD(val.str);
2638                         break;
2639                 case T_Null:
2640                         /* nothing to do */
2641                         break;
2642                 default:
2643                         elog(ERROR, "unrecognized node type: %d",
2644                                  (int) from->type);
2645                         break;
2646         }
2647         return newnode;
2648 }
2649
2650 /*
2651  * copyObject
2652  *
2653  * Create a copy of a Node tree or list.  This is a "deep" copy: all
2654  * substructure is copied too, recursively.
2655  */
2656 void *
2657 copyObject(void *from)
2658 {
2659         void       *retval;
2660
2661         if (from == NULL)
2662                 return NULL;
2663
2664         switch (nodeTag(from))
2665         {
2666                         /*
2667                          * PLAN NODES
2668                          */
2669                 case T_Plan:
2670                         retval = _copyPlan(from);
2671                         break;
2672                 case T_Result:
2673                         retval = _copyResult(from);
2674                         break;
2675                 case T_Append:
2676                         retval = _copyAppend(from);
2677                         break;
2678                 case T_BitmapAnd:
2679                         retval = _copyBitmapAnd(from);
2680                         break;
2681                 case T_BitmapOr:
2682                         retval = _copyBitmapOr(from);
2683                         break;
2684                 case T_Scan:
2685                         retval = _copyScan(from);
2686                         break;
2687                 case T_SeqScan:
2688                         retval = _copySeqScan(from);
2689                         break;
2690                 case T_IndexScan:
2691                         retval = _copyIndexScan(from);
2692                         break;
2693                 case T_BitmapIndexScan:
2694                         retval = _copyBitmapIndexScan(from);
2695                         break;
2696                 case T_BitmapHeapScan:
2697                         retval = _copyBitmapHeapScan(from);
2698                         break;
2699                 case T_TidScan:
2700                         retval = _copyTidScan(from);
2701                         break;
2702                 case T_SubqueryScan:
2703                         retval = _copySubqueryScan(from);
2704                         break;
2705                 case T_FunctionScan:
2706                         retval = _copyFunctionScan(from);
2707                         break;
2708                 case T_Join:
2709                         retval = _copyJoin(from);
2710                         break;
2711                 case T_NestLoop:
2712                         retval = _copyNestLoop(from);
2713                         break;
2714                 case T_MergeJoin:
2715                         retval = _copyMergeJoin(from);
2716                         break;
2717                 case T_HashJoin:
2718                         retval = _copyHashJoin(from);
2719                         break;
2720                 case T_Material:
2721                         retval = _copyMaterial(from);
2722                         break;
2723                 case T_Sort:
2724                         retval = _copySort(from);
2725                         break;
2726                 case T_Group:
2727                         retval = _copyGroup(from);
2728                         break;
2729                 case T_Agg:
2730                         retval = _copyAgg(from);
2731                         break;
2732                 case T_Unique:
2733                         retval = _copyUnique(from);
2734                         break;
2735                 case T_Hash:
2736                         retval = _copyHash(from);
2737                         break;
2738                 case T_SetOp:
2739                         retval = _copySetOp(from);
2740                         break;
2741                 case T_Limit:
2742                         retval = _copyLimit(from);
2743                         break;
2744
2745                         /*
2746                          * PRIMITIVE NODES
2747                          */
2748                 case T_Alias:
2749                         retval = _copyAlias(from);
2750                         break;
2751                 case T_RangeVar:
2752                         retval = _copyRangeVar(from);
2753                         break;
2754                 case T_Var:
2755                         retval = _copyVar(from);
2756                         break;
2757                 case T_Const:
2758                         retval = _copyConst(from);
2759                         break;
2760                 case T_Param:
2761                         retval = _copyParam(from);
2762                         break;
2763                 case T_Aggref:
2764                         retval = _copyAggref(from);
2765                         break;
2766                 case T_ArrayRef:
2767                         retval = _copyArrayRef(from);
2768                         break;
2769                 case T_FuncExpr:
2770                         retval = _copyFuncExpr(from);
2771                         break;
2772                 case T_OpExpr:
2773                         retval = _copyOpExpr(from);
2774                         break;
2775                 case T_DistinctExpr:
2776                         retval = _copyDistinctExpr(from);
2777                         break;
2778                 case T_ScalarArrayOpExpr:
2779                         retval = _copyScalarArrayOpExpr(from);
2780                         break;
2781                 case T_BoolExpr:
2782                         retval = _copyBoolExpr(from);
2783                         break;
2784                 case T_SubLink:
2785                         retval = _copySubLink(from);
2786                         break;
2787                 case T_SubPlan:
2788                         retval = _copySubPlan(from);
2789                         break;
2790                 case T_FieldSelect:
2791                         retval = _copyFieldSelect(from);
2792                         break;
2793                 case T_FieldStore:
2794                         retval = _copyFieldStore(from);
2795                         break;
2796                 case T_RelabelType:
2797                         retval = _copyRelabelType(from);
2798                         break;
2799                 case T_ConvertRowtypeExpr:
2800                         retval = _copyConvertRowtypeExpr(from);
2801                         break;
2802                 case T_CaseExpr:
2803                         retval = _copyCaseExpr(from);
2804                         break;
2805                 case T_CaseWhen:
2806                         retval = _copyCaseWhen(from);
2807                         break;
2808                 case T_CaseTestExpr:
2809                         retval = _copyCaseTestExpr(from);
2810                         break;
2811                 case T_ArrayExpr:
2812                         retval = _copyArrayExpr(from);
2813                         break;
2814                 case T_RowExpr:
2815                         retval = _copyRowExpr(from);
2816                         break;
2817                 case T_CoalesceExpr:
2818                         retval = _copyCoalesceExpr(from);
2819                         break;
2820                 case T_NullIfExpr:
2821                         retval = _copyNullIfExpr(from);
2822                         break;
2823                 case T_NullTest:
2824                         retval = _copyNullTest(from);
2825                         break;
2826                 case T_BooleanTest:
2827                         retval = _copyBooleanTest(from);
2828                         break;
2829                 case T_CoerceToDomain:
2830                         retval = _copyCoerceToDomain(from);
2831                         break;
2832                 case T_CoerceToDomainValue:
2833                         retval = _copyCoerceToDomainValue(from);
2834                         break;
2835                 case T_SetToDefault:
2836                         retval = _copySetToDefault(from);
2837                         break;
2838                 case T_TargetEntry:
2839                         retval = _copyTargetEntry(from);
2840                         break;
2841                 case T_RangeTblRef:
2842                         retval = _copyRangeTblRef(from);
2843                         break;
2844                 case T_JoinExpr:
2845                         retval = _copyJoinExpr(from);
2846                         break;
2847                 case T_FromExpr:
2848                         retval = _copyFromExpr(from);
2849                         break;
2850
2851                         /*
2852                          * RELATION NODES
2853                          */
2854                 case T_PathKeyItem:
2855                         retval = _copyPathKeyItem(from);
2856                         break;
2857                 case T_RestrictInfo:
2858                         retval = _copyRestrictInfo(from);
2859                         break;
2860                 case T_JoinInfo:
2861                         retval = _copyJoinInfo(from);
2862                         break;
2863                 case T_InClauseInfo:
2864                         retval = _copyInClauseInfo(from);
2865                         break;
2866
2867                         /*
2868                          * VALUE NODES
2869                          */
2870                 case T_Integer:
2871                 case T_Float:
2872                 case T_String:
2873                 case T_BitString:
2874                 case T_Null:
2875                         retval = _copyValue(from);
2876                         break;
2877
2878                         /*
2879                          * LIST NODES
2880                          */
2881                 case T_List:
2882                         retval = _copyList(from);
2883                         break;
2884
2885                         /*
2886                          * Lists of integers and OIDs don't need to be deep-copied, so
2887                          * we perform a shallow copy via list_copy()
2888                          */
2889                 case T_IntList:
2890                 case T_OidList:
2891                         retval = list_copy(from);
2892                         break;
2893
2894                         /*
2895                          * PARSE NODES
2896                          */
2897                 case T_Query:
2898                         retval = _copyQuery(from);
2899                         break;
2900                 case T_InsertStmt:
2901                         retval = _copyInsertStmt(from);
2902                         break;
2903                 case T_DeleteStmt:
2904                         retval = _copyDeleteStmt(from);
2905                         break;
2906                 case T_UpdateStmt:
2907                         retval = _copyUpdateStmt(from);
2908                         break;
2909                 case T_SelectStmt:
2910                         retval = _copySelectStmt(from);
2911                         break;
2912                 case T_SetOperationStmt:
2913                         retval = _copySetOperationStmt(from);
2914                         break;
2915                 case T_AlterTableStmt:
2916                         retval = _copyAlterTableStmt(from);
2917                         break;
2918                 case T_AlterTableCmd:
2919                         retval = _copyAlterTableCmd(from);
2920                         break;
2921                 case T_AlterDomainStmt:
2922                         retval = _copyAlterDomainStmt(from);
2923                         break;
2924                 case T_GrantStmt:
2925                         retval = _copyGrantStmt(from);
2926                         break;
2927                 case T_DeclareCursorStmt:
2928                         retval = _copyDeclareCursorStmt(from);
2929                         break;
2930                 case T_ClosePortalStmt:
2931                         retval = _copyClosePortalStmt(from);
2932                         break;
2933                 case T_ClusterStmt:
2934                         retval = _copyClusterStmt(from);
2935                         break;
2936                 case T_CopyStmt:
2937                         retval = _copyCopyStmt(from);
2938                         break;
2939                 case T_CreateStmt:
2940                         retval = _copyCreateStmt(from);
2941                         break;
2942                 case T_InhRelation:
2943                         retval = _copyInhRelation(from);
2944                         break;
2945                 case T_DefineStmt:
2946                         retval = _copyDefineStmt(from);
2947                         break;
2948                 case T_DropStmt:
2949                         retval = _copyDropStmt(from);
2950                         break;
2951                 case T_TruncateStmt:
2952                         retval = _copyTruncateStmt(from);
2953                         break;
2954                 case T_CommentStmt:
2955                         retval = _copyCommentStmt(from);
2956                         break;
2957                 case T_FetchStmt:
2958                         retval = _copyFetchStmt(from);
2959                         break;
2960                 case T_IndexStmt:
2961                         retval = _copyIndexStmt(from);
2962                         break;
2963                 case T_CreateFunctionStmt:
2964                         retval = _copyCreateFunctionStmt(from);
2965                         break;
2966                 case T_FunctionParameter:
2967                         retval = _copyFunctionParameter(from);
2968                         break;
2969                 case T_AlterFunctionStmt:
2970                         retval = _copyAlterFunctionStmt(from);
2971                         break;
2972                 case T_RemoveAggrStmt:
2973                         retval = _copyRemoveAggrStmt(from);
2974                         break;
2975                 case T_RemoveFuncStmt:
2976                         retval = _copyRemoveFuncStmt(from);
2977                         break;
2978                 case T_RemoveOperStmt:
2979                         retval = _copyRemoveOperStmt(from);
2980                         break;
2981                 case T_RemoveOpClassStmt:
2982                         retval = _copyRemoveOpClassStmt(from);
2983                         break;
2984                 case T_RenameStmt:
2985                         retval = _copyRenameStmt(from);
2986                         break;
2987                 case T_AlterOwnerStmt:
2988                         retval = _copyAlterOwnerStmt(from);
2989                         break;
2990                 case T_RuleStmt:
2991                         retval = _copyRuleStmt(from);
2992                         break;
2993                 case T_NotifyStmt:
2994                         retval = _copyNotifyStmt(from);
2995                         break;
2996                 case T_ListenStmt:
2997                         retval = _copyListenStmt(from);
2998                         break;
2999                 case T_UnlistenStmt:
3000                         retval = _copyUnlistenStmt(from);
3001                         break;
3002                 case T_TransactionStmt:
3003                         retval = _copyTransactionStmt(from);
3004                         break;
3005                 case T_CompositeTypeStmt:
3006                         retval = _copyCompositeTypeStmt(from);
3007                         break;
3008                 case T_ViewStmt:
3009                         retval = _copyViewStmt(from);
3010                         break;
3011                 case T_LoadStmt:
3012                         retval = _copyLoadStmt(from);
3013                         break;
3014                 case T_CreateDomainStmt:
3015                         retval = _copyCreateDomainStmt(from);
3016                         break;
3017                 case T_CreateOpClassStmt:
3018                         retval = _copyCreateOpClassStmt(from);
3019                         break;
3020                 case T_CreateOpClassItem:
3021                         retval = _copyCreateOpClassItem(from);
3022                         break;
3023                 case T_CreatedbStmt:
3024                         retval = _copyCreatedbStmt(from);
3025                         break;
3026                 case T_AlterDatabaseSetStmt:
3027                         retval = _copyAlterDatabaseSetStmt(from);
3028                         break;
3029                 case T_DropdbStmt:
3030                         retval = _copyDropdbStmt(from);
3031                         break;
3032                 case T_VacuumStmt:
3033                         retval = _copyVacuumStmt(from);
3034                         break;
3035                 case T_ExplainStmt:
3036                         retval = _copyExplainStmt(from);
3037                         break;
3038                 case T_CreateSeqStmt:
3039                         retval = _copyCreateSeqStmt(from);
3040                         break;
3041                 case T_AlterSeqStmt:
3042                         retval = _copyAlterSeqStmt(from);
3043                         break;
3044                 case T_VariableSetStmt:
3045                         retval = _copyVariableSetStmt(from);
3046                         break;
3047                 case T_VariableShowStmt:
3048                         retval = _copyVariableShowStmt(from);
3049                         break;
3050                 case T_VariableResetStmt:
3051                         retval = _copyVariableResetStmt(from);
3052                         break;
3053                 case T_CreateTableSpaceStmt:
3054                         retval = _copyCreateTableSpaceStmt(from);
3055                         break;
3056                 case T_DropTableSpaceStmt:
3057                         retval = _copyDropTableSpaceStmt(from);
3058                         break;
3059                 case T_CreateTrigStmt:
3060                         retval = _copyCreateTrigStmt(from);
3061                         break;
3062                 case T_DropPropertyStmt:
3063                         retval = _copyDropPropertyStmt(from);
3064                         break;
3065                 case T_CreatePLangStmt:
3066                         retval = _copyCreatePLangStmt(from);
3067                         break;
3068                 case T_DropPLangStmt:
3069                         retval = _copyDropPLangStmt(from);
3070                         break;
3071                 case T_CreateUserStmt:
3072                         retval = _copyCreateUserStmt(from);
3073                         break;
3074                 case T_AlterUserStmt:
3075                         retval = _copyAlterUserStmt(from);
3076                         break;
3077                 case T_AlterUserSetStmt:
3078                         retval = _copyAlterUserSetStmt(from);
3079                         break;
3080                 case T_DropUserStmt:
3081                         retval = _copyDropUserStmt(from);
3082                         break;
3083                 case T_LockStmt:
3084                         retval = _copyLockStmt(from);
3085                         break;
3086                 case T_ConstraintsSetStmt:
3087                         retval = _copyConstraintsSetStmt(from);
3088                         break;
3089                 case T_CreateGroupStmt:
3090                         retval = _copyCreateGroupStmt(from);
3091                         break;
3092                 case T_AlterGroupStmt:
3093                         retval = _copyAlterGroupStmt(from);
3094                         break;
3095                 case T_DropGroupStmt:
3096                         retval = _copyDropGroupStmt(from);
3097                         break;
3098                 case T_ReindexStmt:
3099                         retval = _copyReindexStmt(from);
3100                         break;
3101                 case T_CheckPointStmt:
3102                         retval = (void *) makeNode(CheckPointStmt);
3103                         break;
3104                 case T_CreateSchemaStmt:
3105                         retval = _copyCreateSchemaStmt(from);
3106                         break;
3107                 case T_CreateConversionStmt:
3108                         retval = _copyCreateConversionStmt(from);
3109                         break;
3110                 case T_CreateCastStmt:
3111                         retval = _copyCreateCastStmt(from);
3112                         break;
3113                 case T_DropCastStmt:
3114                         retval = _copyDropCastStmt(from);
3115                         break;
3116                 case T_PrepareStmt:
3117                         retval = _copyPrepareStmt(from);
3118                         break;
3119                 case T_ExecuteStmt:
3120                         retval = _copyExecuteStmt(from);
3121                         break;
3122                 case T_DeallocateStmt:
3123                         retval = _copyDeallocateStmt(from);
3124                         break;
3125
3126                 case T_A_Expr:
3127                         retval = _copyAExpr(from);
3128                         break;
3129                 case T_ColumnRef:
3130                         retval = _copyColumnRef(from);
3131                         break;
3132                 case T_ParamRef:
3133                         retval = _copyParamRef(from);
3134                         break;
3135                 case T_A_Const:
3136                         retval = _copyAConst(from);
3137                         break;
3138                 case T_FuncCall:
3139                         retval = _copyFuncCall(from);
3140                         break;
3141                 case T_A_Indices:
3142                         retval = _copyAIndices(from);
3143                         break;
3144                 case T_A_Indirection:
3145                         retval = _copyA_Indirection(from);
3146                         break;
3147                 case T_ResTarget:
3148                         retval = _copyResTarget(from);
3149                         break;
3150                 case T_TypeCast:
3151                         retval = _copyTypeCast(from);
3152                         break;
3153                 case T_SortBy:
3154                         retval = _copySortBy(from);
3155                         break;
3156                 case T_RangeSubselect:
3157                         retval = _copyRangeSubselect(from);
3158                         break;
3159                 case T_RangeFunction:
3160                         retval = _copyRangeFunction(from);
3161                         break;
3162                 case T_TypeName:
3163                         retval = _copyTypeName(from);
3164                         break;
3165                 case T_IndexElem:
3166                         retval = _copyIndexElem(from);
3167                         break;
3168                 case T_ColumnDef:
3169                         retval = _copyColumnDef(from);
3170                         break;
3171                 case T_Constraint:
3172                         retval = _copyConstraint(from);
3173                         break;
3174                 case T_DefElem:
3175                         retval = _copyDefElem(from);
3176                         break;
3177                 case T_RangeTblEntry:
3178                         retval = _copyRangeTblEntry(from);
3179                         break;
3180                 case T_SortClause:
3181                         retval = _copySortClause(from);
3182                         break;
3183                 case T_GroupClause:
3184                         retval = _copyGroupClause(from);
3185                         break;
3186                 case T_FkConstraint:
3187                         retval = _copyFkConstraint(from);
3188                         break;
3189                 case T_PrivGrantee:
3190                         retval = _copyPrivGrantee(from);
3191                         break;
3192                 case T_FuncWithArgs:
3193                         retval = _copyFuncWithArgs(from);
3194                         break;
3195
3196                 default:
3197                         elog(ERROR, "unrecognized node type: %d", (int) nodeTag(from));
3198                         retval = from;          /* keep compiler quiet */
3199                         break;
3200         }
3201
3202         return retval;
3203 }