1 /*-------------------------------------------------------------------------
4 * Reader functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2013, 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 local_node->fldname = -1 /* set field to "unknown" */
112 /* Read a Node field */
113 #define READ_NODE_FIELD(fldname) \
114 token = pg_strtok(&length); /* skip :fldname */ \
115 (void) token; /* in case not used elsewhere */ \
116 local_node->fldname = nodeRead(NULL, 0)
118 /* Read a bitmapset field */
119 #define READ_BITMAPSET_FIELD(fldname) \
120 token = pg_strtok(&length); /* skip :fldname */ \
121 local_node->fldname = _readBitmapset()
124 #define READ_DONE() \
129 * NOTE: use atoi() to read values written with %d, or atoui() to read
130 * values written with %u in outfuncs.c. An exception is OID values,
131 * for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
132 * but this will probably change in the future.)
134 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
136 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
138 #define strtobool(x) ((*(x) == 't') ? true : false)
140 #define nullable_string(token,length) \
141 ((length) == 0 ? NULL : debackslash(token, length))
144 static Datum readDatum(bool typbyval);
152 Bitmapset *result = NULL;
156 token = pg_strtok(&length);
158 elog(ERROR, "incomplete Bitmapset structure");
159 if (length != 1 || token[0] != '(')
160 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
162 token = pg_strtok(&length);
164 elog(ERROR, "incomplete Bitmapset structure");
165 if (length != 1 || token[0] != 'b')
166 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
173 token = pg_strtok(&length);
175 elog(ERROR, "unterminated Bitmapset structure");
176 if (length == 1 && token[0] == ')')
178 val = (int) strtol(token, &endptr, 10);
179 if (endptr != token + length)
180 elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
181 result = bms_add_member(result, val);
196 READ_ENUM_FIELD(commandType, CmdType);
197 READ_ENUM_FIELD(querySource, QuerySource);
198 local_node->queryId = 0; /* not saved in output format */
199 READ_BOOL_FIELD(canSetTag);
200 READ_NODE_FIELD(utilityStmt);
201 READ_INT_FIELD(resultRelation);
202 READ_BOOL_FIELD(hasAggs);
203 READ_BOOL_FIELD(hasWindowFuncs);
204 READ_BOOL_FIELD(hasSubLinks);
205 READ_BOOL_FIELD(hasDistinctOn);
206 READ_BOOL_FIELD(hasRecursive);
207 READ_BOOL_FIELD(hasModifyingCTE);
208 READ_BOOL_FIELD(hasForUpdate);
209 READ_NODE_FIELD(cteList);
210 READ_NODE_FIELD(rtable);
211 READ_NODE_FIELD(jointree);
212 READ_NODE_FIELD(targetList);
213 READ_NODE_FIELD(withCheckOptions);
214 READ_NODE_FIELD(returningList);
215 READ_NODE_FIELD(groupClause);
216 READ_NODE_FIELD(havingQual);
217 READ_NODE_FIELD(windowClause);
218 READ_NODE_FIELD(distinctClause);
219 READ_NODE_FIELD(sortClause);
220 READ_NODE_FIELD(limitOffset);
221 READ_NODE_FIELD(limitCount);
222 READ_NODE_FIELD(rowMarks);
223 READ_NODE_FIELD(setOperations);
224 READ_NODE_FIELD(constraintDeps);
233 _readNotifyStmt(void)
235 READ_LOCALS(NotifyStmt);
237 READ_STRING_FIELD(conditionname);
238 READ_STRING_FIELD(payload);
244 * _readDeclareCursorStmt
246 static DeclareCursorStmt *
247 _readDeclareCursorStmt(void)
249 READ_LOCALS(DeclareCursorStmt);
251 READ_STRING_FIELD(portalname);
252 READ_INT_FIELD(options);
253 READ_NODE_FIELD(query);
259 * _readWithCheckOption
261 static WithCheckOption *
262 _readWithCheckOption(void)
264 READ_LOCALS(WithCheckOption);
266 READ_STRING_FIELD(viewname);
267 READ_NODE_FIELD(qual);
268 READ_BOOL_FIELD(cascaded);
274 * _readSortGroupClause
276 static SortGroupClause *
277 _readSortGroupClause(void)
279 READ_LOCALS(SortGroupClause);
281 READ_UINT_FIELD(tleSortGroupRef);
282 READ_OID_FIELD(eqop);
283 READ_OID_FIELD(sortop);
284 READ_BOOL_FIELD(nulls_first);
285 READ_BOOL_FIELD(hashable);
293 static WindowClause *
294 _readWindowClause(void)
296 READ_LOCALS(WindowClause);
298 READ_STRING_FIELD(name);
299 READ_STRING_FIELD(refname);
300 READ_NODE_FIELD(partitionClause);
301 READ_NODE_FIELD(orderClause);
302 READ_INT_FIELD(frameOptions);
303 READ_NODE_FIELD(startOffset);
304 READ_NODE_FIELD(endOffset);
305 READ_UINT_FIELD(winref);
306 READ_BOOL_FIELD(copiedOrder);
314 static RowMarkClause *
315 _readRowMarkClause(void)
317 READ_LOCALS(RowMarkClause);
319 READ_UINT_FIELD(rti);
320 READ_ENUM_FIELD(strength, LockClauseStrength);
321 READ_BOOL_FIELD(noWait);
322 READ_BOOL_FIELD(pushedDown);
328 * _readCommonTableExpr
330 static CommonTableExpr *
331 _readCommonTableExpr(void)
333 READ_LOCALS(CommonTableExpr);
335 READ_STRING_FIELD(ctename);
336 READ_NODE_FIELD(aliascolnames);
337 READ_NODE_FIELD(ctequery);
338 READ_LOCATION_FIELD(location);
339 READ_BOOL_FIELD(cterecursive);
340 READ_INT_FIELD(cterefcount);
341 READ_NODE_FIELD(ctecolnames);
342 READ_NODE_FIELD(ctecoltypes);
343 READ_NODE_FIELD(ctecoltypmods);
344 READ_NODE_FIELD(ctecolcollations);
350 * _readSetOperationStmt
352 static SetOperationStmt *
353 _readSetOperationStmt(void)
355 READ_LOCALS(SetOperationStmt);
357 READ_ENUM_FIELD(op, SetOperation);
358 READ_BOOL_FIELD(all);
359 READ_NODE_FIELD(larg);
360 READ_NODE_FIELD(rarg);
361 READ_NODE_FIELD(colTypes);
362 READ_NODE_FIELD(colTypmods);
363 READ_NODE_FIELD(colCollations);
364 READ_NODE_FIELD(groupClauses);
371 * Stuff from primnodes.h.
379 READ_STRING_FIELD(aliasname);
380 READ_NODE_FIELD(colnames);
388 READ_LOCALS(RangeVar);
390 local_node->catalogname = NULL; /* not currently saved in output
393 READ_STRING_FIELD(schemaname);
394 READ_STRING_FIELD(relname);
395 READ_ENUM_FIELD(inhOpt, InhOption);
396 READ_CHAR_FIELD(relpersistence);
397 READ_NODE_FIELD(alias);
398 READ_LOCATION_FIELD(location);
404 _readIntoClause(void)
406 READ_LOCALS(IntoClause);
408 READ_NODE_FIELD(rel);
409 READ_NODE_FIELD(colNames);
410 READ_NODE_FIELD(options);
411 READ_ENUM_FIELD(onCommit, OnCommitAction);
412 READ_STRING_FIELD(tableSpaceName);
413 READ_NODE_FIELD(viewQuery);
414 READ_BOOL_FIELD(skipData);
427 READ_UINT_FIELD(varno);
428 READ_INT_FIELD(varattno);
429 READ_OID_FIELD(vartype);
430 READ_INT_FIELD(vartypmod);
431 READ_OID_FIELD(varcollid);
432 READ_UINT_FIELD(varlevelsup);
433 READ_UINT_FIELD(varnoold);
434 READ_INT_FIELD(varoattno);
435 READ_LOCATION_FIELD(location);
448 READ_OID_FIELD(consttype);
449 READ_INT_FIELD(consttypmod);
450 READ_OID_FIELD(constcollid);
451 READ_INT_FIELD(constlen);
452 READ_BOOL_FIELD(constbyval);
453 READ_BOOL_FIELD(constisnull);
454 READ_LOCATION_FIELD(location);
456 token = pg_strtok(&length); /* skip :constvalue */
457 if (local_node->constisnull)
458 token = pg_strtok(&length); /* skip "<>" */
460 local_node->constvalue = readDatum(local_node->constbyval);
473 READ_ENUM_FIELD(paramkind, ParamKind);
474 READ_INT_FIELD(paramid);
475 READ_OID_FIELD(paramtype);
476 READ_INT_FIELD(paramtypmod);
477 READ_OID_FIELD(paramcollid);
478 READ_LOCATION_FIELD(location);
491 READ_OID_FIELD(aggfnoid);
492 READ_OID_FIELD(aggtype);
493 READ_OID_FIELD(aggcollid);
494 READ_OID_FIELD(inputcollid);
495 READ_NODE_FIELD(args);
496 READ_NODE_FIELD(aggorder);
497 READ_NODE_FIELD(aggdistinct);
498 READ_NODE_FIELD(aggfilter);
499 READ_BOOL_FIELD(aggstar);
500 READ_BOOL_FIELD(aggvariadic);
501 READ_UINT_FIELD(agglevelsup);
502 READ_LOCATION_FIELD(location);
511 _readWindowFunc(void)
513 READ_LOCALS(WindowFunc);
515 READ_OID_FIELD(winfnoid);
516 READ_OID_FIELD(wintype);
517 READ_OID_FIELD(wincollid);
518 READ_OID_FIELD(inputcollid);
519 READ_NODE_FIELD(args);
520 READ_NODE_FIELD(aggfilter);
521 READ_UINT_FIELD(winref);
522 READ_BOOL_FIELD(winstar);
523 READ_BOOL_FIELD(winagg);
524 READ_LOCATION_FIELD(location);
535 READ_LOCALS(ArrayRef);
537 READ_OID_FIELD(refarraytype);
538 READ_OID_FIELD(refelemtype);
539 READ_INT_FIELD(reftypmod);
540 READ_OID_FIELD(refcollid);
541 READ_NODE_FIELD(refupperindexpr);
542 READ_NODE_FIELD(reflowerindexpr);
543 READ_NODE_FIELD(refexpr);
544 READ_NODE_FIELD(refassgnexpr);
555 READ_LOCALS(FuncExpr);
557 READ_OID_FIELD(funcid);
558 READ_OID_FIELD(funcresulttype);
559 READ_BOOL_FIELD(funcretset);
560 READ_BOOL_FIELD(funcvariadic);
561 READ_ENUM_FIELD(funcformat, CoercionForm);
562 READ_OID_FIELD(funccollid);
563 READ_OID_FIELD(inputcollid);
564 READ_NODE_FIELD(args);
565 READ_LOCATION_FIELD(location);
573 static NamedArgExpr *
574 _readNamedArgExpr(void)
576 READ_LOCALS(NamedArgExpr);
578 READ_NODE_FIELD(arg);
579 READ_STRING_FIELD(name);
580 READ_INT_FIELD(argnumber);
581 READ_LOCATION_FIELD(location);
594 READ_OID_FIELD(opno);
595 READ_OID_FIELD(opfuncid);
598 * The opfuncid is stored in the textual format primarily for debugging
599 * and documentation reasons. We want to always read it as zero to force
600 * it to be re-looked-up in the pg_operator entry. This ensures that
601 * stored rules don't have hidden dependencies on operators' functions.
602 * (We don't currently support an ALTER OPERATOR command, but might
605 local_node->opfuncid = InvalidOid;
607 READ_OID_FIELD(opresulttype);
608 READ_BOOL_FIELD(opretset);
609 READ_OID_FIELD(opcollid);
610 READ_OID_FIELD(inputcollid);
611 READ_NODE_FIELD(args);
612 READ_LOCATION_FIELD(location);
620 static DistinctExpr *
621 _readDistinctExpr(void)
623 READ_LOCALS(DistinctExpr);
625 READ_OID_FIELD(opno);
626 READ_OID_FIELD(opfuncid);
629 * The opfuncid is stored in the textual format primarily for debugging
630 * and documentation reasons. We want to always read it as zero to force
631 * it to be re-looked-up in the pg_operator entry. This ensures that
632 * stored rules don't have hidden dependencies on operators' functions.
633 * (We don't currently support an ALTER OPERATOR command, but might
636 local_node->opfuncid = InvalidOid;
638 READ_OID_FIELD(opresulttype);
639 READ_BOOL_FIELD(opretset);
640 READ_OID_FIELD(opcollid);
641 READ_OID_FIELD(inputcollid);
642 READ_NODE_FIELD(args);
643 READ_LOCATION_FIELD(location);
652 _readNullIfExpr(void)
654 READ_LOCALS(NullIfExpr);
656 READ_OID_FIELD(opno);
657 READ_OID_FIELD(opfuncid);
660 * The opfuncid is stored in the textual format primarily for debugging
661 * and documentation reasons. We want to always read it as zero to force
662 * it to be re-looked-up in the pg_operator entry. This ensures that
663 * stored rules don't have hidden dependencies on operators' functions.
664 * (We don't currently support an ALTER OPERATOR command, but might
667 local_node->opfuncid = InvalidOid;
669 READ_OID_FIELD(opresulttype);
670 READ_BOOL_FIELD(opretset);
671 READ_OID_FIELD(opcollid);
672 READ_OID_FIELD(inputcollid);
673 READ_NODE_FIELD(args);
674 READ_LOCATION_FIELD(location);
680 * _readScalarArrayOpExpr
682 static ScalarArrayOpExpr *
683 _readScalarArrayOpExpr(void)
685 READ_LOCALS(ScalarArrayOpExpr);
687 READ_OID_FIELD(opno);
688 READ_OID_FIELD(opfuncid);
691 * The opfuncid is stored in the textual format primarily for debugging
692 * and documentation reasons. We want to always read it as zero to force
693 * it to be re-looked-up in the pg_operator entry. This ensures that
694 * stored rules don't have hidden dependencies on operators' functions.
695 * (We don't currently support an ALTER OPERATOR command, but might
698 local_node->opfuncid = InvalidOid;
700 READ_BOOL_FIELD(useOr);
701 READ_OID_FIELD(inputcollid);
702 READ_NODE_FIELD(args);
703 READ_LOCATION_FIELD(location);
714 READ_LOCALS(BoolExpr);
716 /* do-it-yourself enum representation */
717 token = pg_strtok(&length); /* skip :boolop */
718 token = pg_strtok(&length); /* get field value */
719 if (strncmp(token, "and", 3) == 0)
720 local_node->boolop = AND_EXPR;
721 else if (strncmp(token, "or", 2) == 0)
722 local_node->boolop = OR_EXPR;
723 else if (strncmp(token, "not", 3) == 0)
724 local_node->boolop = NOT_EXPR;
726 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
728 READ_NODE_FIELD(args);
729 READ_LOCATION_FIELD(location);
740 READ_LOCALS(SubLink);
742 READ_ENUM_FIELD(subLinkType, SubLinkType);
743 READ_NODE_FIELD(testexpr);
744 READ_NODE_FIELD(operName);
745 READ_NODE_FIELD(subselect);
746 READ_LOCATION_FIELD(location);
752 * _readSubPlan is not needed since it doesn't appear in stored rules.
759 _readFieldSelect(void)
761 READ_LOCALS(FieldSelect);
763 READ_NODE_FIELD(arg);
764 READ_INT_FIELD(fieldnum);
765 READ_OID_FIELD(resulttype);
766 READ_INT_FIELD(resulttypmod);
767 READ_OID_FIELD(resultcollid);
776 _readFieldStore(void)
778 READ_LOCALS(FieldStore);
780 READ_NODE_FIELD(arg);
781 READ_NODE_FIELD(newvals);
782 READ_NODE_FIELD(fieldnums);
783 READ_OID_FIELD(resulttype);
792 _readRelabelType(void)
794 READ_LOCALS(RelabelType);
796 READ_NODE_FIELD(arg);
797 READ_OID_FIELD(resulttype);
798 READ_INT_FIELD(resulttypmod);
799 READ_OID_FIELD(resultcollid);
800 READ_ENUM_FIELD(relabelformat, CoercionForm);
801 READ_LOCATION_FIELD(location);
810 _readCoerceViaIO(void)
812 READ_LOCALS(CoerceViaIO);
814 READ_NODE_FIELD(arg);
815 READ_OID_FIELD(resulttype);
816 READ_OID_FIELD(resultcollid);
817 READ_ENUM_FIELD(coerceformat, CoercionForm);
818 READ_LOCATION_FIELD(location);
824 * _readArrayCoerceExpr
826 static ArrayCoerceExpr *
827 _readArrayCoerceExpr(void)
829 READ_LOCALS(ArrayCoerceExpr);
831 READ_NODE_FIELD(arg);
832 READ_OID_FIELD(elemfuncid);
833 READ_OID_FIELD(resulttype);
834 READ_INT_FIELD(resulttypmod);
835 READ_OID_FIELD(resultcollid);
836 READ_BOOL_FIELD(isExplicit);
837 READ_ENUM_FIELD(coerceformat, CoercionForm);
838 READ_LOCATION_FIELD(location);
844 * _readConvertRowtypeExpr
846 static ConvertRowtypeExpr *
847 _readConvertRowtypeExpr(void)
849 READ_LOCALS(ConvertRowtypeExpr);
851 READ_NODE_FIELD(arg);
852 READ_OID_FIELD(resulttype);
853 READ_ENUM_FIELD(convertformat, CoercionForm);
854 READ_LOCATION_FIELD(location);
863 _readCollateExpr(void)
865 READ_LOCALS(CollateExpr);
867 READ_NODE_FIELD(arg);
868 READ_OID_FIELD(collOid);
869 READ_LOCATION_FIELD(location);
880 READ_LOCALS(CaseExpr);
882 READ_OID_FIELD(casetype);
883 READ_OID_FIELD(casecollid);
884 READ_NODE_FIELD(arg);
885 READ_NODE_FIELD(args);
886 READ_NODE_FIELD(defresult);
887 READ_LOCATION_FIELD(location);
898 READ_LOCALS(CaseWhen);
900 READ_NODE_FIELD(expr);
901 READ_NODE_FIELD(result);
902 READ_LOCATION_FIELD(location);
910 static CaseTestExpr *
911 _readCaseTestExpr(void)
913 READ_LOCALS(CaseTestExpr);
915 READ_OID_FIELD(typeId);
916 READ_INT_FIELD(typeMod);
917 READ_OID_FIELD(collation);
928 READ_LOCALS(ArrayExpr);
930 READ_OID_FIELD(array_typeid);
931 READ_OID_FIELD(array_collid);
932 READ_OID_FIELD(element_typeid);
933 READ_NODE_FIELD(elements);
934 READ_BOOL_FIELD(multidims);
935 READ_LOCATION_FIELD(location);
946 READ_LOCALS(RowExpr);
948 READ_NODE_FIELD(args);
949 READ_OID_FIELD(row_typeid);
950 READ_ENUM_FIELD(row_format, CoercionForm);
951 READ_NODE_FIELD(colnames);
952 READ_LOCATION_FIELD(location);
958 * _readRowCompareExpr
960 static RowCompareExpr *
961 _readRowCompareExpr(void)
963 READ_LOCALS(RowCompareExpr);
965 READ_ENUM_FIELD(rctype, RowCompareType);
966 READ_NODE_FIELD(opnos);
967 READ_NODE_FIELD(opfamilies);
968 READ_NODE_FIELD(inputcollids);
969 READ_NODE_FIELD(largs);
970 READ_NODE_FIELD(rargs);
978 static CoalesceExpr *
979 _readCoalesceExpr(void)
981 READ_LOCALS(CoalesceExpr);
983 READ_OID_FIELD(coalescetype);
984 READ_OID_FIELD(coalescecollid);
985 READ_NODE_FIELD(args);
986 READ_LOCATION_FIELD(location);
995 _readMinMaxExpr(void)
997 READ_LOCALS(MinMaxExpr);
999 READ_OID_FIELD(minmaxtype);
1000 READ_OID_FIELD(minmaxcollid);
1001 READ_OID_FIELD(inputcollid);
1002 READ_ENUM_FIELD(op, MinMaxOp);
1003 READ_NODE_FIELD(args);
1004 READ_LOCATION_FIELD(location);
1015 READ_LOCALS(XmlExpr);
1017 READ_ENUM_FIELD(op, XmlExprOp);
1018 READ_STRING_FIELD(name);
1019 READ_NODE_FIELD(named_args);
1020 READ_NODE_FIELD(arg_names);
1021 READ_NODE_FIELD(args);
1022 READ_ENUM_FIELD(xmloption, XmlOptionType);
1023 READ_OID_FIELD(type);
1024 READ_INT_FIELD(typmod);
1025 READ_LOCATION_FIELD(location);
1036 READ_LOCALS(NullTest);
1038 READ_NODE_FIELD(arg);
1039 READ_ENUM_FIELD(nulltesttype, NullTestType);
1040 READ_BOOL_FIELD(argisrow);
1048 static BooleanTest *
1049 _readBooleanTest(void)
1051 READ_LOCALS(BooleanTest);
1053 READ_NODE_FIELD(arg);
1054 READ_ENUM_FIELD(booltesttype, BoolTestType);
1060 * _readCoerceToDomain
1062 static CoerceToDomain *
1063 _readCoerceToDomain(void)
1065 READ_LOCALS(CoerceToDomain);
1067 READ_NODE_FIELD(arg);
1068 READ_OID_FIELD(resulttype);
1069 READ_INT_FIELD(resulttypmod);
1070 READ_OID_FIELD(resultcollid);
1071 READ_ENUM_FIELD(coercionformat, CoercionForm);
1072 READ_LOCATION_FIELD(location);
1078 * _readCoerceToDomainValue
1080 static CoerceToDomainValue *
1081 _readCoerceToDomainValue(void)
1083 READ_LOCALS(CoerceToDomainValue);
1085 READ_OID_FIELD(typeId);
1086 READ_INT_FIELD(typeMod);
1087 READ_OID_FIELD(collation);
1088 READ_LOCATION_FIELD(location);
1096 static SetToDefault *
1097 _readSetToDefault(void)
1099 READ_LOCALS(SetToDefault);
1101 READ_OID_FIELD(typeId);
1102 READ_INT_FIELD(typeMod);
1103 READ_OID_FIELD(collation);
1104 READ_LOCATION_FIELD(location);
1110 * _readCurrentOfExpr
1112 static CurrentOfExpr *
1113 _readCurrentOfExpr(void)
1115 READ_LOCALS(CurrentOfExpr);
1117 READ_UINT_FIELD(cvarno);
1118 READ_STRING_FIELD(cursor_name);
1119 READ_INT_FIELD(cursor_param);
1127 static TargetEntry *
1128 _readTargetEntry(void)
1130 READ_LOCALS(TargetEntry);
1132 READ_NODE_FIELD(expr);
1133 READ_INT_FIELD(resno);
1134 READ_STRING_FIELD(resname);
1135 READ_UINT_FIELD(ressortgroupref);
1136 READ_OID_FIELD(resorigtbl);
1137 READ_INT_FIELD(resorigcol);
1138 READ_BOOL_FIELD(resjunk);
1146 static RangeTblRef *
1147 _readRangeTblRef(void)
1149 READ_LOCALS(RangeTblRef);
1151 READ_INT_FIELD(rtindex);
1162 READ_LOCALS(JoinExpr);
1164 READ_ENUM_FIELD(jointype, JoinType);
1165 READ_BOOL_FIELD(isNatural);
1166 READ_NODE_FIELD(larg);
1167 READ_NODE_FIELD(rarg);
1168 READ_NODE_FIELD(usingClause);
1169 READ_NODE_FIELD(quals);
1170 READ_NODE_FIELD(alias);
1171 READ_INT_FIELD(rtindex);
1182 READ_LOCALS(FromExpr);
1184 READ_NODE_FIELD(fromlist);
1185 READ_NODE_FIELD(quals);
1192 * Stuff from parsenodes.h.
1196 * _readRangeTblEntry
1198 static RangeTblEntry *
1199 _readRangeTblEntry(void)
1201 READ_LOCALS(RangeTblEntry);
1203 /* put alias + eref first to make dump more legible */
1204 READ_NODE_FIELD(alias);
1205 READ_NODE_FIELD(eref);
1206 READ_ENUM_FIELD(rtekind, RTEKind);
1208 switch (local_node->rtekind)
1211 READ_OID_FIELD(relid);
1212 READ_CHAR_FIELD(relkind);
1215 READ_NODE_FIELD(subquery);
1216 READ_BOOL_FIELD(security_barrier);
1219 READ_ENUM_FIELD(jointype, JoinType);
1220 READ_NODE_FIELD(joinaliasvars);
1223 READ_NODE_FIELD(funcexpr);
1224 READ_NODE_FIELD(funccoltypes);
1225 READ_NODE_FIELD(funccoltypmods);
1226 READ_NODE_FIELD(funccolcollations);
1227 READ_BOOL_FIELD(funcordinality);
1230 READ_NODE_FIELD(values_lists);
1231 READ_NODE_FIELD(values_collations);
1234 READ_STRING_FIELD(ctename);
1235 READ_UINT_FIELD(ctelevelsup);
1236 READ_BOOL_FIELD(self_reference);
1237 READ_NODE_FIELD(ctecoltypes);
1238 READ_NODE_FIELD(ctecoltypmods);
1239 READ_NODE_FIELD(ctecolcollations);
1242 elog(ERROR, "unrecognized RTE kind: %d",
1243 (int) local_node->rtekind);
1247 READ_BOOL_FIELD(lateral);
1248 READ_BOOL_FIELD(inh);
1249 READ_BOOL_FIELD(inFromCl);
1250 READ_UINT_FIELD(requiredPerms);
1251 READ_OID_FIELD(checkAsUser);
1252 READ_BITMAPSET_FIELD(selectedCols);
1253 READ_BITMAPSET_FIELD(modifiedCols);
1262 * Given a character string representing a node tree, parseNodeString creates
1263 * the internal node structure.
1265 * The string to be read must already have been loaded into pg_strtok().
1268 parseNodeString(void)
1274 token = pg_strtok(&length);
1276 #define MATCH(tokname, namelen) \
1277 (length == namelen && memcmp(token, tokname, namelen) == 0)
1279 if (MATCH("QUERY", 5))
1280 return_value = _readQuery();
1281 else if (MATCH("WITHCHECKOPTION", 15))
1282 return_value = _readWithCheckOption();
1283 else if (MATCH("SORTGROUPCLAUSE", 15))
1284 return_value = _readSortGroupClause();
1285 else if (MATCH("WINDOWCLAUSE", 12))
1286 return_value = _readWindowClause();
1287 else if (MATCH("ROWMARKCLAUSE", 13))
1288 return_value = _readRowMarkClause();
1289 else if (MATCH("COMMONTABLEEXPR", 15))
1290 return_value = _readCommonTableExpr();
1291 else if (MATCH("SETOPERATIONSTMT", 16))
1292 return_value = _readSetOperationStmt();
1293 else if (MATCH("ALIAS", 5))
1294 return_value = _readAlias();
1295 else if (MATCH("RANGEVAR", 8))
1296 return_value = _readRangeVar();
1297 else if (MATCH("INTOCLAUSE", 10))
1298 return_value = _readIntoClause();
1299 else if (MATCH("VAR", 3))
1300 return_value = _readVar();
1301 else if (MATCH("CONST", 5))
1302 return_value = _readConst();
1303 else if (MATCH("PARAM", 5))
1304 return_value = _readParam();
1305 else if (MATCH("AGGREF", 6))
1306 return_value = _readAggref();
1307 else if (MATCH("WINDOWFUNC", 10))
1308 return_value = _readWindowFunc();
1309 else if (MATCH("ARRAYREF", 8))
1310 return_value = _readArrayRef();
1311 else if (MATCH("FUNCEXPR", 8))
1312 return_value = _readFuncExpr();
1313 else if (MATCH("NAMEDARGEXPR", 12))
1314 return_value = _readNamedArgExpr();
1315 else if (MATCH("OPEXPR", 6))
1316 return_value = _readOpExpr();
1317 else if (MATCH("DISTINCTEXPR", 12))
1318 return_value = _readDistinctExpr();
1319 else if (MATCH("NULLIFEXPR", 10))
1320 return_value = _readNullIfExpr();
1321 else if (MATCH("SCALARARRAYOPEXPR", 17))
1322 return_value = _readScalarArrayOpExpr();
1323 else if (MATCH("BOOLEXPR", 8))
1324 return_value = _readBoolExpr();
1325 else if (MATCH("SUBLINK", 7))
1326 return_value = _readSubLink();
1327 else if (MATCH("FIELDSELECT", 11))
1328 return_value = _readFieldSelect();
1329 else if (MATCH("FIELDSTORE", 10))
1330 return_value = _readFieldStore();
1331 else if (MATCH("RELABELTYPE", 11))
1332 return_value = _readRelabelType();
1333 else if (MATCH("COERCEVIAIO", 11))
1334 return_value = _readCoerceViaIO();
1335 else if (MATCH("ARRAYCOERCEEXPR", 15))
1336 return_value = _readArrayCoerceExpr();
1337 else if (MATCH("CONVERTROWTYPEEXPR", 18))
1338 return_value = _readConvertRowtypeExpr();
1339 else if (MATCH("COLLATE", 7))
1340 return_value = _readCollateExpr();
1341 else if (MATCH("CASE", 4))
1342 return_value = _readCaseExpr();
1343 else if (MATCH("WHEN", 4))
1344 return_value = _readCaseWhen();
1345 else if (MATCH("CASETESTEXPR", 12))
1346 return_value = _readCaseTestExpr();
1347 else if (MATCH("ARRAY", 5))
1348 return_value = _readArrayExpr();
1349 else if (MATCH("ROW", 3))
1350 return_value = _readRowExpr();
1351 else if (MATCH("ROWCOMPARE", 10))
1352 return_value = _readRowCompareExpr();
1353 else if (MATCH("COALESCE", 8))
1354 return_value = _readCoalesceExpr();
1355 else if (MATCH("MINMAX", 6))
1356 return_value = _readMinMaxExpr();
1357 else if (MATCH("XMLEXPR", 7))
1358 return_value = _readXmlExpr();
1359 else if (MATCH("NULLTEST", 8))
1360 return_value = _readNullTest();
1361 else if (MATCH("BOOLEANTEST", 11))
1362 return_value = _readBooleanTest();
1363 else if (MATCH("COERCETODOMAIN", 14))
1364 return_value = _readCoerceToDomain();
1365 else if (MATCH("COERCETODOMAINVALUE", 19))
1366 return_value = _readCoerceToDomainValue();
1367 else if (MATCH("SETTODEFAULT", 12))
1368 return_value = _readSetToDefault();
1369 else if (MATCH("CURRENTOFEXPR", 13))
1370 return_value = _readCurrentOfExpr();
1371 else if (MATCH("TARGETENTRY", 11))
1372 return_value = _readTargetEntry();
1373 else if (MATCH("RANGETBLREF", 11))
1374 return_value = _readRangeTblRef();
1375 else if (MATCH("JOINEXPR", 8))
1376 return_value = _readJoinExpr();
1377 else if (MATCH("FROMEXPR", 8))
1378 return_value = _readFromExpr();
1379 else if (MATCH("RTE", 3))
1380 return_value = _readRangeTblEntry();
1381 else if (MATCH("NOTIFY", 6))
1382 return_value = _readNotifyStmt();
1383 else if (MATCH("DECLARECURSOR", 13))
1384 return_value = _readDeclareCursorStmt();
1387 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
1388 return_value = NULL; /* keep compiler quiet */
1391 return (Node *) return_value;
1398 * Given a string representation of a constant, recreate the appropriate
1399 * Datum. The string representation embeds length info, but not byValue,
1400 * so we must be told that.
1403 readDatum(bool typbyval)
1413 * read the actual length of the value
1415 token = pg_strtok(&tokenLength);
1416 length = atoui(token);
1418 token = pg_strtok(&tokenLength); /* read the '[' */
1419 if (token == NULL || token[0] != '[')
1420 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu",
1421 token ? (const char *) token : "[NULL]",
1422 (unsigned long) length);
1426 if (length > (Size) sizeof(Datum))
1427 elog(ERROR, "byval datum but length = %lu",
1428 (unsigned long) length);
1430 s = (char *) (&res);
1431 for (i = 0; i < (Size) sizeof(Datum); i++)
1433 token = pg_strtok(&tokenLength);
1434 s[i] = (char) atoi(token);
1437 else if (length <= 0)
1441 s = (char *) palloc(length);
1442 for (i = 0; i < length; i++)
1444 token = pg_strtok(&tokenLength);
1445 s[i] = (char) atoi(token);
1447 res = PointerGetDatum(s);
1450 token = pg_strtok(&tokenLength); /* read the ']' */
1451 if (token == NULL || token[0] != ']')
1452 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu",
1453 token ? (const char *) token : "[NULL]",
1454 (unsigned long) length);