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