1 /*-------------------------------------------------------------------------
4 * Reader functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group
7 * Portions Copyright (c) 1994, Regents of the University of California
11 * src/backend/nodes/readfuncs.c
14 * Path and Plan nodes do not have any readfuncs support, because we
15 * never have occasion to read them in. (There was once code here that
16 * claimed to read them, but it was broken as well as unused.) We
17 * never read executor state trees, either.
19 * Parse location fields are written out by outfuncs.c, but only for
20 * possible debugging use. When reading a location field, we discard
21 * the stored value and set the location field to -1 (ie, "unknown").
22 * This is because nodes coming from a stored rule should not be thought
23 * to have a known location in the current query's text.
25 *-------------------------------------------------------------------------
31 #include "nodes/parsenodes.h"
32 #include "nodes/readfuncs.h"
36 * Macros to simplify reading of different kinds of fields. Use these
37 * wherever possible to reduce the chance for silly typos. Note that these
38 * hard-wire conventions about the names of the local variables in a Read
42 /* Macros for declaring appropriate local variables */
44 /* A few guys need only local_node */
45 #define READ_LOCALS_NO_FIELDS(nodeTypeName) \
46 nodeTypeName *local_node = makeNode(nodeTypeName)
48 /* And a few guys need only the pg_strtok support fields */
49 #define READ_TEMP_LOCALS() \
53 /* ... but most need both */
54 #define READ_LOCALS(nodeTypeName) \
55 READ_LOCALS_NO_FIELDS(nodeTypeName); \
58 /* Read an integer field (anything written as ":fldname %d") */
59 #define READ_INT_FIELD(fldname) \
60 token = pg_strtok(&length); /* skip :fldname */ \
61 token = pg_strtok(&length); /* get field value */ \
62 local_node->fldname = atoi(token)
64 /* Read an unsigned integer field (anything written as ":fldname %u") */
65 #define READ_UINT_FIELD(fldname) \
66 token = pg_strtok(&length); /* skip :fldname */ \
67 token = pg_strtok(&length); /* get field value */ \
68 local_node->fldname = atoui(token)
70 /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
71 #define READ_OID_FIELD(fldname) \
72 token = pg_strtok(&length); /* skip :fldname */ \
73 token = pg_strtok(&length); /* get field value */ \
74 local_node->fldname = atooid(token)
76 /* Read a char field (ie, one ascii character) */
77 #define READ_CHAR_FIELD(fldname) \
78 token = pg_strtok(&length); /* skip :fldname */ \
79 token = pg_strtok(&length); /* get field value */ \
80 local_node->fldname = token[0]
82 /* Read an enumerated-type field that was written as an integer code */
83 #define READ_ENUM_FIELD(fldname, enumtype) \
84 token = pg_strtok(&length); /* skip :fldname */ \
85 token = pg_strtok(&length); /* get field value */ \
86 local_node->fldname = (enumtype) atoi(token)
88 /* Read a float field */
89 #define READ_FLOAT_FIELD(fldname) \
90 token = pg_strtok(&length); /* skip :fldname */ \
91 token = pg_strtok(&length); /* get field value */ \
92 local_node->fldname = atof(token)
94 /* Read a boolean field */
95 #define READ_BOOL_FIELD(fldname) \
96 token = pg_strtok(&length); /* skip :fldname */ \
97 token = pg_strtok(&length); /* get field value */ \
98 local_node->fldname = strtobool(token)
100 /* Read a character-string field */
101 #define READ_STRING_FIELD(fldname) \
102 token = pg_strtok(&length); /* skip :fldname */ \
103 token = pg_strtok(&length); /* get field value */ \
104 local_node->fldname = nullable_string(token, length)
106 /* Read a parse location field (and throw away the value, per notes above) */
107 #define READ_LOCATION_FIELD(fldname) \
108 token = pg_strtok(&length); /* skip :fldname */ \
109 token = pg_strtok(&length); /* get field value */ \
110 (void) token; /* in case not used elsewhere */ \
111 local_node->fldname = -1 /* set field to "unknown" */
113 /* Read a Node field */
114 #define READ_NODE_FIELD(fldname) \
115 token = pg_strtok(&length); /* skip :fldname */ \
116 (void) token; /* in case not used elsewhere */ \
117 local_node->fldname = nodeRead(NULL, 0)
119 /* Read a bitmapset field */
120 #define READ_BITMAPSET_FIELD(fldname) \
121 token = pg_strtok(&length); /* skip :fldname */ \
122 (void) token; /* in case not used elsewhere */ \
123 local_node->fldname = _readBitmapset()
126 #define READ_DONE() \
131 * NOTE: use atoi() to read values written with %d, or atoui() to read
132 * values written with %u in outfuncs.c. An exception is OID values,
133 * for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
134 * but this will probably change in the future.)
136 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
138 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
140 #define strtobool(x) ((*(x) == 't') ? true : false)
142 #define nullable_string(token,length) \
143 ((length) == 0 ? NULL : debackslash(token, length))
146 static Datum readDatum(bool typbyval);
154 Bitmapset *result = NULL;
158 token = pg_strtok(&length);
160 elog(ERROR, "incomplete Bitmapset structure");
161 if (length != 1 || token[0] != '(')
162 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
164 token = pg_strtok(&length);
166 elog(ERROR, "incomplete Bitmapset structure");
167 if (length != 1 || token[0] != 'b')
168 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
175 token = pg_strtok(&length);
177 elog(ERROR, "unterminated Bitmapset structure");
178 if (length == 1 && token[0] == ')')
180 val = (int) strtol(token, &endptr, 10);
181 if (endptr != token + length)
182 elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
183 result = bms_add_member(result, val);
198 READ_ENUM_FIELD(commandType, CmdType);
199 READ_ENUM_FIELD(querySource, QuerySource);
200 local_node->queryId = 0; /* not saved in output format */
201 READ_BOOL_FIELD(canSetTag);
202 READ_NODE_FIELD(utilityStmt);
203 READ_INT_FIELD(resultRelation);
204 READ_BOOL_FIELD(hasAggs);
205 READ_BOOL_FIELD(hasWindowFuncs);
206 READ_BOOL_FIELD(hasSubLinks);
207 READ_BOOL_FIELD(hasDistinctOn);
208 READ_BOOL_FIELD(hasRecursive);
209 READ_BOOL_FIELD(hasModifyingCTE);
210 READ_BOOL_FIELD(hasForUpdate);
211 READ_BOOL_FIELD(hasRowSecurity);
212 READ_NODE_FIELD(cteList);
213 READ_NODE_FIELD(rtable);
214 READ_NODE_FIELD(jointree);
215 READ_NODE_FIELD(targetList);
216 READ_NODE_FIELD(withCheckOptions);
217 READ_NODE_FIELD(returningList);
218 READ_NODE_FIELD(groupClause);
219 READ_NODE_FIELD(havingQual);
220 READ_NODE_FIELD(windowClause);
221 READ_NODE_FIELD(distinctClause);
222 READ_NODE_FIELD(sortClause);
223 READ_NODE_FIELD(limitOffset);
224 READ_NODE_FIELD(limitCount);
225 READ_NODE_FIELD(rowMarks);
226 READ_NODE_FIELD(setOperations);
227 READ_NODE_FIELD(constraintDeps);
236 _readNotifyStmt(void)
238 READ_LOCALS(NotifyStmt);
240 READ_STRING_FIELD(conditionname);
241 READ_STRING_FIELD(payload);
247 * _readDeclareCursorStmt
249 static DeclareCursorStmt *
250 _readDeclareCursorStmt(void)
252 READ_LOCALS(DeclareCursorStmt);
254 READ_STRING_FIELD(portalname);
255 READ_INT_FIELD(options);
256 READ_NODE_FIELD(query);
262 * _readWithCheckOption
264 static WithCheckOption *
265 _readWithCheckOption(void)
267 READ_LOCALS(WithCheckOption);
269 READ_STRING_FIELD(viewname);
270 READ_NODE_FIELD(qual);
271 READ_BOOL_FIELD(cascaded);
277 * _readSortGroupClause
279 static SortGroupClause *
280 _readSortGroupClause(void)
282 READ_LOCALS(SortGroupClause);
284 READ_UINT_FIELD(tleSortGroupRef);
285 READ_OID_FIELD(eqop);
286 READ_OID_FIELD(sortop);
287 READ_BOOL_FIELD(nulls_first);
288 READ_BOOL_FIELD(hashable);
296 static WindowClause *
297 _readWindowClause(void)
299 READ_LOCALS(WindowClause);
301 READ_STRING_FIELD(name);
302 READ_STRING_FIELD(refname);
303 READ_NODE_FIELD(partitionClause);
304 READ_NODE_FIELD(orderClause);
305 READ_INT_FIELD(frameOptions);
306 READ_NODE_FIELD(startOffset);
307 READ_NODE_FIELD(endOffset);
308 READ_UINT_FIELD(winref);
309 READ_BOOL_FIELD(copiedOrder);
317 static RowMarkClause *
318 _readRowMarkClause(void)
320 READ_LOCALS(RowMarkClause);
322 READ_UINT_FIELD(rti);
323 READ_ENUM_FIELD(strength, LockClauseStrength);
324 READ_ENUM_FIELD(waitPolicy, LockWaitPolicy);
325 READ_BOOL_FIELD(pushedDown);
331 * _readCommonTableExpr
333 static CommonTableExpr *
334 _readCommonTableExpr(void)
336 READ_LOCALS(CommonTableExpr);
338 READ_STRING_FIELD(ctename);
339 READ_NODE_FIELD(aliascolnames);
340 READ_NODE_FIELD(ctequery);
341 READ_LOCATION_FIELD(location);
342 READ_BOOL_FIELD(cterecursive);
343 READ_INT_FIELD(cterefcount);
344 READ_NODE_FIELD(ctecolnames);
345 READ_NODE_FIELD(ctecoltypes);
346 READ_NODE_FIELD(ctecoltypmods);
347 READ_NODE_FIELD(ctecolcollations);
353 * _readSetOperationStmt
355 static SetOperationStmt *
356 _readSetOperationStmt(void)
358 READ_LOCALS(SetOperationStmt);
360 READ_ENUM_FIELD(op, SetOperation);
361 READ_BOOL_FIELD(all);
362 READ_NODE_FIELD(larg);
363 READ_NODE_FIELD(rarg);
364 READ_NODE_FIELD(colTypes);
365 READ_NODE_FIELD(colTypmods);
366 READ_NODE_FIELD(colCollations);
367 READ_NODE_FIELD(groupClauses);
374 * Stuff from primnodes.h.
382 READ_STRING_FIELD(aliasname);
383 READ_NODE_FIELD(colnames);
391 READ_LOCALS(RangeVar);
393 local_node->catalogname = NULL; /* not currently saved in output
396 READ_STRING_FIELD(schemaname);
397 READ_STRING_FIELD(relname);
398 READ_ENUM_FIELD(inhOpt, InhOption);
399 READ_CHAR_FIELD(relpersistence);
400 READ_NODE_FIELD(alias);
401 READ_LOCATION_FIELD(location);
407 _readIntoClause(void)
409 READ_LOCALS(IntoClause);
411 READ_NODE_FIELD(rel);
412 READ_NODE_FIELD(colNames);
413 READ_NODE_FIELD(options);
414 READ_ENUM_FIELD(onCommit, OnCommitAction);
415 READ_STRING_FIELD(tableSpaceName);
416 READ_NODE_FIELD(viewQuery);
417 READ_BOOL_FIELD(skipData);
430 READ_UINT_FIELD(varno);
431 READ_INT_FIELD(varattno);
432 READ_OID_FIELD(vartype);
433 READ_INT_FIELD(vartypmod);
434 READ_OID_FIELD(varcollid);
435 READ_UINT_FIELD(varlevelsup);
436 READ_UINT_FIELD(varnoold);
437 READ_INT_FIELD(varoattno);
438 READ_LOCATION_FIELD(location);
451 READ_OID_FIELD(consttype);
452 READ_INT_FIELD(consttypmod);
453 READ_OID_FIELD(constcollid);
454 READ_INT_FIELD(constlen);
455 READ_BOOL_FIELD(constbyval);
456 READ_BOOL_FIELD(constisnull);
457 READ_LOCATION_FIELD(location);
459 token = pg_strtok(&length); /* skip :constvalue */
460 if (local_node->constisnull)
461 token = pg_strtok(&length); /* skip "<>" */
463 local_node->constvalue = readDatum(local_node->constbyval);
476 READ_ENUM_FIELD(paramkind, ParamKind);
477 READ_INT_FIELD(paramid);
478 READ_OID_FIELD(paramtype);
479 READ_INT_FIELD(paramtypmod);
480 READ_OID_FIELD(paramcollid);
481 READ_LOCATION_FIELD(location);
494 READ_OID_FIELD(aggfnoid);
495 READ_OID_FIELD(aggtype);
496 READ_OID_FIELD(aggcollid);
497 READ_OID_FIELD(inputcollid);
498 READ_NODE_FIELD(aggdirectargs);
499 READ_NODE_FIELD(args);
500 READ_NODE_FIELD(aggorder);
501 READ_NODE_FIELD(aggdistinct);
502 READ_NODE_FIELD(aggfilter);
503 READ_BOOL_FIELD(aggstar);
504 READ_BOOL_FIELD(aggvariadic);
505 READ_CHAR_FIELD(aggkind);
506 READ_UINT_FIELD(agglevelsup);
507 READ_LOCATION_FIELD(location);
516 _readWindowFunc(void)
518 READ_LOCALS(WindowFunc);
520 READ_OID_FIELD(winfnoid);
521 READ_OID_FIELD(wintype);
522 READ_OID_FIELD(wincollid);
523 READ_OID_FIELD(inputcollid);
524 READ_NODE_FIELD(args);
525 READ_NODE_FIELD(aggfilter);
526 READ_UINT_FIELD(winref);
527 READ_BOOL_FIELD(winstar);
528 READ_BOOL_FIELD(winagg);
529 READ_LOCATION_FIELD(location);
540 READ_LOCALS(ArrayRef);
542 READ_OID_FIELD(refarraytype);
543 READ_OID_FIELD(refelemtype);
544 READ_INT_FIELD(reftypmod);
545 READ_OID_FIELD(refcollid);
546 READ_NODE_FIELD(refupperindexpr);
547 READ_NODE_FIELD(reflowerindexpr);
548 READ_NODE_FIELD(refexpr);
549 READ_NODE_FIELD(refassgnexpr);
560 READ_LOCALS(FuncExpr);
562 READ_OID_FIELD(funcid);
563 READ_OID_FIELD(funcresulttype);
564 READ_BOOL_FIELD(funcretset);
565 READ_BOOL_FIELD(funcvariadic);
566 READ_ENUM_FIELD(funcformat, CoercionForm);
567 READ_OID_FIELD(funccollid);
568 READ_OID_FIELD(inputcollid);
569 READ_NODE_FIELD(args);
570 READ_LOCATION_FIELD(location);
578 static NamedArgExpr *
579 _readNamedArgExpr(void)
581 READ_LOCALS(NamedArgExpr);
583 READ_NODE_FIELD(arg);
584 READ_STRING_FIELD(name);
585 READ_INT_FIELD(argnumber);
586 READ_LOCATION_FIELD(location);
599 READ_OID_FIELD(opno);
600 READ_OID_FIELD(opfuncid);
603 * The opfuncid is stored in the textual format primarily for debugging
604 * and documentation reasons. We want to always read it as zero to force
605 * it to be re-looked-up in the pg_operator entry. This ensures that
606 * stored rules don't have hidden dependencies on operators' functions.
607 * (We don't currently support an ALTER OPERATOR command, but might
610 local_node->opfuncid = InvalidOid;
612 READ_OID_FIELD(opresulttype);
613 READ_BOOL_FIELD(opretset);
614 READ_OID_FIELD(opcollid);
615 READ_OID_FIELD(inputcollid);
616 READ_NODE_FIELD(args);
617 READ_LOCATION_FIELD(location);
625 static DistinctExpr *
626 _readDistinctExpr(void)
628 READ_LOCALS(DistinctExpr);
630 READ_OID_FIELD(opno);
631 READ_OID_FIELD(opfuncid);
634 * The opfuncid is stored in the textual format primarily for debugging
635 * and documentation reasons. We want to always read it as zero to force
636 * it to be re-looked-up in the pg_operator entry. This ensures that
637 * stored rules don't have hidden dependencies on operators' functions.
638 * (We don't currently support an ALTER OPERATOR command, but might
641 local_node->opfuncid = InvalidOid;
643 READ_OID_FIELD(opresulttype);
644 READ_BOOL_FIELD(opretset);
645 READ_OID_FIELD(opcollid);
646 READ_OID_FIELD(inputcollid);
647 READ_NODE_FIELD(args);
648 READ_LOCATION_FIELD(location);
657 _readNullIfExpr(void)
659 READ_LOCALS(NullIfExpr);
661 READ_OID_FIELD(opno);
662 READ_OID_FIELD(opfuncid);
665 * The opfuncid is stored in the textual format primarily for debugging
666 * and documentation reasons. We want to always read it as zero to force
667 * it to be re-looked-up in the pg_operator entry. This ensures that
668 * stored rules don't have hidden dependencies on operators' functions.
669 * (We don't currently support an ALTER OPERATOR command, but might
672 local_node->opfuncid = InvalidOid;
674 READ_OID_FIELD(opresulttype);
675 READ_BOOL_FIELD(opretset);
676 READ_OID_FIELD(opcollid);
677 READ_OID_FIELD(inputcollid);
678 READ_NODE_FIELD(args);
679 READ_LOCATION_FIELD(location);
685 * _readScalarArrayOpExpr
687 static ScalarArrayOpExpr *
688 _readScalarArrayOpExpr(void)
690 READ_LOCALS(ScalarArrayOpExpr);
692 READ_OID_FIELD(opno);
693 READ_OID_FIELD(opfuncid);
696 * The opfuncid is stored in the textual format primarily for debugging
697 * and documentation reasons. We want to always read it as zero to force
698 * it to be re-looked-up in the pg_operator entry. This ensures that
699 * stored rules don't have hidden dependencies on operators' functions.
700 * (We don't currently support an ALTER OPERATOR command, but might
703 local_node->opfuncid = InvalidOid;
705 READ_BOOL_FIELD(useOr);
706 READ_OID_FIELD(inputcollid);
707 READ_NODE_FIELD(args);
708 READ_LOCATION_FIELD(location);
719 READ_LOCALS(BoolExpr);
721 /* do-it-yourself enum representation */
722 token = pg_strtok(&length); /* skip :boolop */
723 token = pg_strtok(&length); /* get field value */
724 if (strncmp(token, "and", 3) == 0)
725 local_node->boolop = AND_EXPR;
726 else if (strncmp(token, "or", 2) == 0)
727 local_node->boolop = OR_EXPR;
728 else if (strncmp(token, "not", 3) == 0)
729 local_node->boolop = NOT_EXPR;
731 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
733 READ_NODE_FIELD(args);
734 READ_LOCATION_FIELD(location);
745 READ_LOCALS(SubLink);
747 READ_ENUM_FIELD(subLinkType, SubLinkType);
748 READ_INT_FIELD(subLinkId);
749 READ_NODE_FIELD(testexpr);
750 READ_NODE_FIELD(operName);
751 READ_NODE_FIELD(subselect);
752 READ_LOCATION_FIELD(location);
758 * _readSubPlan is not needed since it doesn't appear in stored rules.
765 _readFieldSelect(void)
767 READ_LOCALS(FieldSelect);
769 READ_NODE_FIELD(arg);
770 READ_INT_FIELD(fieldnum);
771 READ_OID_FIELD(resulttype);
772 READ_INT_FIELD(resulttypmod);
773 READ_OID_FIELD(resultcollid);
782 _readFieldStore(void)
784 READ_LOCALS(FieldStore);
786 READ_NODE_FIELD(arg);
787 READ_NODE_FIELD(newvals);
788 READ_NODE_FIELD(fieldnums);
789 READ_OID_FIELD(resulttype);
798 _readRelabelType(void)
800 READ_LOCALS(RelabelType);
802 READ_NODE_FIELD(arg);
803 READ_OID_FIELD(resulttype);
804 READ_INT_FIELD(resulttypmod);
805 READ_OID_FIELD(resultcollid);
806 READ_ENUM_FIELD(relabelformat, CoercionForm);
807 READ_LOCATION_FIELD(location);
816 _readCoerceViaIO(void)
818 READ_LOCALS(CoerceViaIO);
820 READ_NODE_FIELD(arg);
821 READ_OID_FIELD(resulttype);
822 READ_OID_FIELD(resultcollid);
823 READ_ENUM_FIELD(coerceformat, CoercionForm);
824 READ_LOCATION_FIELD(location);
830 * _readArrayCoerceExpr
832 static ArrayCoerceExpr *
833 _readArrayCoerceExpr(void)
835 READ_LOCALS(ArrayCoerceExpr);
837 READ_NODE_FIELD(arg);
838 READ_OID_FIELD(elemfuncid);
839 READ_OID_FIELD(resulttype);
840 READ_INT_FIELD(resulttypmod);
841 READ_OID_FIELD(resultcollid);
842 READ_BOOL_FIELD(isExplicit);
843 READ_ENUM_FIELD(coerceformat, CoercionForm);
844 READ_LOCATION_FIELD(location);
850 * _readConvertRowtypeExpr
852 static ConvertRowtypeExpr *
853 _readConvertRowtypeExpr(void)
855 READ_LOCALS(ConvertRowtypeExpr);
857 READ_NODE_FIELD(arg);
858 READ_OID_FIELD(resulttype);
859 READ_ENUM_FIELD(convertformat, CoercionForm);
860 READ_LOCATION_FIELD(location);
869 _readCollateExpr(void)
871 READ_LOCALS(CollateExpr);
873 READ_NODE_FIELD(arg);
874 READ_OID_FIELD(collOid);
875 READ_LOCATION_FIELD(location);
886 READ_LOCALS(CaseExpr);
888 READ_OID_FIELD(casetype);
889 READ_OID_FIELD(casecollid);
890 READ_NODE_FIELD(arg);
891 READ_NODE_FIELD(args);
892 READ_NODE_FIELD(defresult);
893 READ_LOCATION_FIELD(location);
904 READ_LOCALS(CaseWhen);
906 READ_NODE_FIELD(expr);
907 READ_NODE_FIELD(result);
908 READ_LOCATION_FIELD(location);
916 static CaseTestExpr *
917 _readCaseTestExpr(void)
919 READ_LOCALS(CaseTestExpr);
921 READ_OID_FIELD(typeId);
922 READ_INT_FIELD(typeMod);
923 READ_OID_FIELD(collation);
934 READ_LOCALS(ArrayExpr);
936 READ_OID_FIELD(array_typeid);
937 READ_OID_FIELD(array_collid);
938 READ_OID_FIELD(element_typeid);
939 READ_NODE_FIELD(elements);
940 READ_BOOL_FIELD(multidims);
941 READ_LOCATION_FIELD(location);
952 READ_LOCALS(RowExpr);
954 READ_NODE_FIELD(args);
955 READ_OID_FIELD(row_typeid);
956 READ_ENUM_FIELD(row_format, CoercionForm);
957 READ_NODE_FIELD(colnames);
958 READ_LOCATION_FIELD(location);
964 * _readRowCompareExpr
966 static RowCompareExpr *
967 _readRowCompareExpr(void)
969 READ_LOCALS(RowCompareExpr);
971 READ_ENUM_FIELD(rctype, RowCompareType);
972 READ_NODE_FIELD(opnos);
973 READ_NODE_FIELD(opfamilies);
974 READ_NODE_FIELD(inputcollids);
975 READ_NODE_FIELD(largs);
976 READ_NODE_FIELD(rargs);
984 static CoalesceExpr *
985 _readCoalesceExpr(void)
987 READ_LOCALS(CoalesceExpr);
989 READ_OID_FIELD(coalescetype);
990 READ_OID_FIELD(coalescecollid);
991 READ_NODE_FIELD(args);
992 READ_LOCATION_FIELD(location);
1001 _readMinMaxExpr(void)
1003 READ_LOCALS(MinMaxExpr);
1005 READ_OID_FIELD(minmaxtype);
1006 READ_OID_FIELD(minmaxcollid);
1007 READ_OID_FIELD(inputcollid);
1008 READ_ENUM_FIELD(op, MinMaxOp);
1009 READ_NODE_FIELD(args);
1010 READ_LOCATION_FIELD(location);
1021 READ_LOCALS(XmlExpr);
1023 READ_ENUM_FIELD(op, XmlExprOp);
1024 READ_STRING_FIELD(name);
1025 READ_NODE_FIELD(named_args);
1026 READ_NODE_FIELD(arg_names);
1027 READ_NODE_FIELD(args);
1028 READ_ENUM_FIELD(xmloption, XmlOptionType);
1029 READ_OID_FIELD(type);
1030 READ_INT_FIELD(typmod);
1031 READ_LOCATION_FIELD(location);
1042 READ_LOCALS(NullTest);
1044 READ_NODE_FIELD(arg);
1045 READ_ENUM_FIELD(nulltesttype, NullTestType);
1046 READ_BOOL_FIELD(argisrow);
1047 READ_LOCATION_FIELD(location);
1055 static BooleanTest *
1056 _readBooleanTest(void)
1058 READ_LOCALS(BooleanTest);
1060 READ_NODE_FIELD(arg);
1061 READ_ENUM_FIELD(booltesttype, BoolTestType);
1062 READ_LOCATION_FIELD(location);
1068 * _readCoerceToDomain
1070 static CoerceToDomain *
1071 _readCoerceToDomain(void)
1073 READ_LOCALS(CoerceToDomain);
1075 READ_NODE_FIELD(arg);
1076 READ_OID_FIELD(resulttype);
1077 READ_INT_FIELD(resulttypmod);
1078 READ_OID_FIELD(resultcollid);
1079 READ_ENUM_FIELD(coercionformat, CoercionForm);
1080 READ_LOCATION_FIELD(location);
1086 * _readCoerceToDomainValue
1088 static CoerceToDomainValue *
1089 _readCoerceToDomainValue(void)
1091 READ_LOCALS(CoerceToDomainValue);
1093 READ_OID_FIELD(typeId);
1094 READ_INT_FIELD(typeMod);
1095 READ_OID_FIELD(collation);
1096 READ_LOCATION_FIELD(location);
1104 static SetToDefault *
1105 _readSetToDefault(void)
1107 READ_LOCALS(SetToDefault);
1109 READ_OID_FIELD(typeId);
1110 READ_INT_FIELD(typeMod);
1111 READ_OID_FIELD(collation);
1112 READ_LOCATION_FIELD(location);
1118 * _readCurrentOfExpr
1120 static CurrentOfExpr *
1121 _readCurrentOfExpr(void)
1123 READ_LOCALS(CurrentOfExpr);
1125 READ_UINT_FIELD(cvarno);
1126 READ_STRING_FIELD(cursor_name);
1127 READ_INT_FIELD(cursor_param);
1135 static TargetEntry *
1136 _readTargetEntry(void)
1138 READ_LOCALS(TargetEntry);
1140 READ_NODE_FIELD(expr);
1141 READ_INT_FIELD(resno);
1142 READ_STRING_FIELD(resname);
1143 READ_UINT_FIELD(ressortgroupref);
1144 READ_OID_FIELD(resorigtbl);
1145 READ_INT_FIELD(resorigcol);
1146 READ_BOOL_FIELD(resjunk);
1154 static RangeTblRef *
1155 _readRangeTblRef(void)
1157 READ_LOCALS(RangeTblRef);
1159 READ_INT_FIELD(rtindex);
1170 READ_LOCALS(JoinExpr);
1172 READ_ENUM_FIELD(jointype, JoinType);
1173 READ_BOOL_FIELD(isNatural);
1174 READ_NODE_FIELD(larg);
1175 READ_NODE_FIELD(rarg);
1176 READ_NODE_FIELD(usingClause);
1177 READ_NODE_FIELD(quals);
1178 READ_NODE_FIELD(alias);
1179 READ_INT_FIELD(rtindex);
1190 READ_LOCALS(FromExpr);
1192 READ_NODE_FIELD(fromlist);
1193 READ_NODE_FIELD(quals);
1200 * Stuff from parsenodes.h.
1204 * _readRangeTblEntry
1206 static RangeTblEntry *
1207 _readRangeTblEntry(void)
1209 READ_LOCALS(RangeTblEntry);
1211 /* put alias + eref first to make dump more legible */
1212 READ_NODE_FIELD(alias);
1213 READ_NODE_FIELD(eref);
1214 READ_ENUM_FIELD(rtekind, RTEKind);
1216 switch (local_node->rtekind)
1219 READ_OID_FIELD(relid);
1220 READ_CHAR_FIELD(relkind);
1223 READ_NODE_FIELD(subquery);
1224 READ_BOOL_FIELD(security_barrier);
1227 READ_ENUM_FIELD(jointype, JoinType);
1228 READ_NODE_FIELD(joinaliasvars);
1231 READ_NODE_FIELD(functions);
1232 READ_BOOL_FIELD(funcordinality);
1235 READ_NODE_FIELD(values_lists);
1236 READ_NODE_FIELD(values_collations);
1239 READ_STRING_FIELD(ctename);
1240 READ_UINT_FIELD(ctelevelsup);
1241 READ_BOOL_FIELD(self_reference);
1242 READ_NODE_FIELD(ctecoltypes);
1243 READ_NODE_FIELD(ctecoltypmods);
1244 READ_NODE_FIELD(ctecolcollations);
1247 elog(ERROR, "unrecognized RTE kind: %d",
1248 (int) local_node->rtekind);
1252 READ_BOOL_FIELD(lateral);
1253 READ_BOOL_FIELD(inh);
1254 READ_BOOL_FIELD(inFromCl);
1255 READ_UINT_FIELD(requiredPerms);
1256 READ_OID_FIELD(checkAsUser);
1257 READ_BITMAPSET_FIELD(selectedCols);
1258 READ_BITMAPSET_FIELD(modifiedCols);
1259 READ_NODE_FIELD(securityQuals);
1265 * _readRangeTblFunction
1267 static RangeTblFunction *
1268 _readRangeTblFunction(void)
1270 READ_LOCALS(RangeTblFunction);
1272 READ_NODE_FIELD(funcexpr);
1273 READ_INT_FIELD(funccolcount);
1274 READ_NODE_FIELD(funccolnames);
1275 READ_NODE_FIELD(funccoltypes);
1276 READ_NODE_FIELD(funccoltypmods);
1277 READ_NODE_FIELD(funccolcollations);
1278 READ_BITMAPSET_FIELD(funcparams);
1287 * Given a character string representing a node tree, parseNodeString creates
1288 * the internal node structure.
1290 * The string to be read must already have been loaded into pg_strtok().
1293 parseNodeString(void)
1299 token = pg_strtok(&length);
1301 #define MATCH(tokname, namelen) \
1302 (length == namelen && memcmp(token, tokname, namelen) == 0)
1304 if (MATCH("QUERY", 5))
1305 return_value = _readQuery();
1306 else if (MATCH("WITHCHECKOPTION", 15))
1307 return_value = _readWithCheckOption();
1308 else if (MATCH("SORTGROUPCLAUSE", 15))
1309 return_value = _readSortGroupClause();
1310 else if (MATCH("WINDOWCLAUSE", 12))
1311 return_value = _readWindowClause();
1312 else if (MATCH("ROWMARKCLAUSE", 13))
1313 return_value = _readRowMarkClause();
1314 else if (MATCH("COMMONTABLEEXPR", 15))
1315 return_value = _readCommonTableExpr();
1316 else if (MATCH("SETOPERATIONSTMT", 16))
1317 return_value = _readSetOperationStmt();
1318 else if (MATCH("ALIAS", 5))
1319 return_value = _readAlias();
1320 else if (MATCH("RANGEVAR", 8))
1321 return_value = _readRangeVar();
1322 else if (MATCH("INTOCLAUSE", 10))
1323 return_value = _readIntoClause();
1324 else if (MATCH("VAR", 3))
1325 return_value = _readVar();
1326 else if (MATCH("CONST", 5))
1327 return_value = _readConst();
1328 else if (MATCH("PARAM", 5))
1329 return_value = _readParam();
1330 else if (MATCH("AGGREF", 6))
1331 return_value = _readAggref();
1332 else if (MATCH("WINDOWFUNC", 10))
1333 return_value = _readWindowFunc();
1334 else if (MATCH("ARRAYREF", 8))
1335 return_value = _readArrayRef();
1336 else if (MATCH("FUNCEXPR", 8))
1337 return_value = _readFuncExpr();
1338 else if (MATCH("NAMEDARGEXPR", 12))
1339 return_value = _readNamedArgExpr();
1340 else if (MATCH("OPEXPR", 6))
1341 return_value = _readOpExpr();
1342 else if (MATCH("DISTINCTEXPR", 12))
1343 return_value = _readDistinctExpr();
1344 else if (MATCH("NULLIFEXPR", 10))
1345 return_value = _readNullIfExpr();
1346 else if (MATCH("SCALARARRAYOPEXPR", 17))
1347 return_value = _readScalarArrayOpExpr();
1348 else if (MATCH("BOOLEXPR", 8))
1349 return_value = _readBoolExpr();
1350 else if (MATCH("SUBLINK", 7))
1351 return_value = _readSubLink();
1352 else if (MATCH("FIELDSELECT", 11))
1353 return_value = _readFieldSelect();
1354 else if (MATCH("FIELDSTORE", 10))
1355 return_value = _readFieldStore();
1356 else if (MATCH("RELABELTYPE", 11))
1357 return_value = _readRelabelType();
1358 else if (MATCH("COERCEVIAIO", 11))
1359 return_value = _readCoerceViaIO();
1360 else if (MATCH("ARRAYCOERCEEXPR", 15))
1361 return_value = _readArrayCoerceExpr();
1362 else if (MATCH("CONVERTROWTYPEEXPR", 18))
1363 return_value = _readConvertRowtypeExpr();
1364 else if (MATCH("COLLATE", 7))
1365 return_value = _readCollateExpr();
1366 else if (MATCH("CASE", 4))
1367 return_value = _readCaseExpr();
1368 else if (MATCH("WHEN", 4))
1369 return_value = _readCaseWhen();
1370 else if (MATCH("CASETESTEXPR", 12))
1371 return_value = _readCaseTestExpr();
1372 else if (MATCH("ARRAY", 5))
1373 return_value = _readArrayExpr();
1374 else if (MATCH("ROW", 3))
1375 return_value = _readRowExpr();
1376 else if (MATCH("ROWCOMPARE", 10))
1377 return_value = _readRowCompareExpr();
1378 else if (MATCH("COALESCE", 8))
1379 return_value = _readCoalesceExpr();
1380 else if (MATCH("MINMAX", 6))
1381 return_value = _readMinMaxExpr();
1382 else if (MATCH("XMLEXPR", 7))
1383 return_value = _readXmlExpr();
1384 else if (MATCH("NULLTEST", 8))
1385 return_value = _readNullTest();
1386 else if (MATCH("BOOLEANTEST", 11))
1387 return_value = _readBooleanTest();
1388 else if (MATCH("COERCETODOMAIN", 14))
1389 return_value = _readCoerceToDomain();
1390 else if (MATCH("COERCETODOMAINVALUE", 19))
1391 return_value = _readCoerceToDomainValue();
1392 else if (MATCH("SETTODEFAULT", 12))
1393 return_value = _readSetToDefault();
1394 else if (MATCH("CURRENTOFEXPR", 13))
1395 return_value = _readCurrentOfExpr();
1396 else if (MATCH("TARGETENTRY", 11))
1397 return_value = _readTargetEntry();
1398 else if (MATCH("RANGETBLREF", 11))
1399 return_value = _readRangeTblRef();
1400 else if (MATCH("JOINEXPR", 8))
1401 return_value = _readJoinExpr();
1402 else if (MATCH("FROMEXPR", 8))
1403 return_value = _readFromExpr();
1404 else if (MATCH("RTE", 3))
1405 return_value = _readRangeTblEntry();
1406 else if (MATCH("RANGETBLFUNCTION", 16))
1407 return_value = _readRangeTblFunction();
1408 else if (MATCH("NOTIFY", 6))
1409 return_value = _readNotifyStmt();
1410 else if (MATCH("DECLARECURSOR", 13))
1411 return_value = _readDeclareCursorStmt();
1414 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
1415 return_value = NULL; /* keep compiler quiet */
1418 return (Node *) return_value;
1425 * Given a string representation of a constant, recreate the appropriate
1426 * Datum. The string representation embeds length info, but not byValue,
1427 * so we must be told that.
1430 readDatum(bool typbyval)
1440 * read the actual length of the value
1442 token = pg_strtok(&tokenLength);
1443 length = atoui(token);
1445 token = pg_strtok(&tokenLength); /* read the '[' */
1446 if (token == NULL || token[0] != '[')
1447 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %zu",
1448 token ? (const char *) token : "[NULL]", length);
1452 if (length > (Size) sizeof(Datum))
1453 elog(ERROR, "byval datum but length = %zu", length);
1455 s = (char *) (&res);
1456 for (i = 0; i < (Size) sizeof(Datum); i++)
1458 token = pg_strtok(&tokenLength);
1459 s[i] = (char) atoi(token);
1462 else if (length <= 0)
1466 s = (char *) palloc(length);
1467 for (i = 0; i < length; i++)
1469 token = pg_strtok(&tokenLength);
1470 s[i] = (char) atoi(token);
1472 res = PointerGetDatum(s);
1475 token = pg_strtok(&tokenLength); /* read the ']' */
1476 if (token == NULL || token[0] != ']')
1477 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %zu",
1478 token ? (const char *) token : "[NULL]", length);