1 /*-------------------------------------------------------------------------
4 * Reader functions for Postgres tree nodes.
6 * Portions Copyright (c) 1996-2011, 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() \
52 (void) token /* possibly unused */
54 /* ... but most need both */
55 #define READ_LOCALS(nodeTypeName) \
56 READ_LOCALS_NO_FIELDS(nodeTypeName); \
59 /* Read an integer field (anything written as ":fldname %d") */
60 #define READ_INT_FIELD(fldname) \
61 token = pg_strtok(&length); /* skip :fldname */ \
62 token = pg_strtok(&length); /* get field value */ \
63 local_node->fldname = atoi(token)
65 /* Read an unsigned integer field (anything written as ":fldname %u") */
66 #define READ_UINT_FIELD(fldname) \
67 token = pg_strtok(&length); /* skip :fldname */ \
68 token = pg_strtok(&length); /* get field value */ \
69 local_node->fldname = atoui(token)
71 /* Read an OID field (don't hard-wire assumption that OID is same as uint) */
72 #define READ_OID_FIELD(fldname) \
73 token = pg_strtok(&length); /* skip :fldname */ \
74 token = pg_strtok(&length); /* get field value */ \
75 local_node->fldname = atooid(token)
77 /* Read a char field (ie, one ascii character) */
78 #define READ_CHAR_FIELD(fldname) \
79 token = pg_strtok(&length); /* skip :fldname */ \
80 token = pg_strtok(&length); /* get field value */ \
81 local_node->fldname = token[0]
83 /* Read an enumerated-type field that was written as an integer code */
84 #define READ_ENUM_FIELD(fldname, enumtype) \
85 token = pg_strtok(&length); /* skip :fldname */ \
86 token = pg_strtok(&length); /* get field value */ \
87 local_node->fldname = (enumtype) atoi(token)
89 /* Read a float field */
90 #define READ_FLOAT_FIELD(fldname) \
91 token = pg_strtok(&length); /* skip :fldname */ \
92 token = pg_strtok(&length); /* get field value */ \
93 local_node->fldname = atof(token)
95 /* Read a boolean field */
96 #define READ_BOOL_FIELD(fldname) \
97 token = pg_strtok(&length); /* skip :fldname */ \
98 token = pg_strtok(&length); /* get field value */ \
99 local_node->fldname = strtobool(token)
101 /* Read a character-string field */
102 #define READ_STRING_FIELD(fldname) \
103 token = pg_strtok(&length); /* skip :fldname */ \
104 token = pg_strtok(&length); /* get field value */ \
105 local_node->fldname = nullable_string(token, length)
107 /* Read a parse location field (and throw away the value, per notes above) */
108 #define READ_LOCATION_FIELD(fldname) \
109 token = pg_strtok(&length); /* skip :fldname */ \
110 token = pg_strtok(&length); /* get field value */ \
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 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 READ_BOOL_FIELD(canSetTag);
199 READ_NODE_FIELD(utilityStmt);
200 READ_INT_FIELD(resultRelation);
201 READ_NODE_FIELD(intoClause);
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(returningList);
214 READ_NODE_FIELD(groupClause);
215 READ_NODE_FIELD(havingQual);
216 READ_NODE_FIELD(windowClause);
217 READ_NODE_FIELD(distinctClause);
218 READ_NODE_FIELD(sortClause);
219 READ_NODE_FIELD(limitOffset);
220 READ_NODE_FIELD(limitCount);
221 READ_NODE_FIELD(rowMarks);
222 READ_NODE_FIELD(setOperations);
223 READ_NODE_FIELD(constraintDeps);
232 _readNotifyStmt(void)
234 READ_LOCALS(NotifyStmt);
236 READ_STRING_FIELD(conditionname);
237 READ_STRING_FIELD(payload);
243 * _readDeclareCursorStmt
245 static DeclareCursorStmt *
246 _readDeclareCursorStmt(void)
248 READ_LOCALS(DeclareCursorStmt);
250 READ_STRING_FIELD(portalname);
251 READ_INT_FIELD(options);
252 READ_NODE_FIELD(query);
258 * _readSortGroupClause
260 static SortGroupClause *
261 _readSortGroupClause(void)
263 READ_LOCALS(SortGroupClause);
265 READ_UINT_FIELD(tleSortGroupRef);
266 READ_OID_FIELD(eqop);
267 READ_OID_FIELD(sortop);
268 READ_BOOL_FIELD(nulls_first);
269 READ_BOOL_FIELD(hashable);
277 static WindowClause *
278 _readWindowClause(void)
280 READ_LOCALS(WindowClause);
282 READ_STRING_FIELD(name);
283 READ_STRING_FIELD(refname);
284 READ_NODE_FIELD(partitionClause);
285 READ_NODE_FIELD(orderClause);
286 READ_INT_FIELD(frameOptions);
287 READ_NODE_FIELD(startOffset);
288 READ_NODE_FIELD(endOffset);
289 READ_UINT_FIELD(winref);
290 READ_BOOL_FIELD(copiedOrder);
298 static RowMarkClause *
299 _readRowMarkClause(void)
301 READ_LOCALS(RowMarkClause);
303 READ_UINT_FIELD(rti);
304 READ_BOOL_FIELD(forUpdate);
305 READ_BOOL_FIELD(noWait);
306 READ_BOOL_FIELD(pushedDown);
312 * _readCommonTableExpr
314 static CommonTableExpr *
315 _readCommonTableExpr(void)
317 READ_LOCALS(CommonTableExpr);
319 READ_STRING_FIELD(ctename);
320 READ_NODE_FIELD(aliascolnames);
321 READ_NODE_FIELD(ctequery);
322 READ_LOCATION_FIELD(location);
323 READ_BOOL_FIELD(cterecursive);
324 READ_INT_FIELD(cterefcount);
325 READ_NODE_FIELD(ctecolnames);
326 READ_NODE_FIELD(ctecoltypes);
327 READ_NODE_FIELD(ctecoltypmods);
328 READ_NODE_FIELD(ctecolcollations);
334 * _readSetOperationStmt
336 static SetOperationStmt *
337 _readSetOperationStmt(void)
339 READ_LOCALS(SetOperationStmt);
341 READ_ENUM_FIELD(op, SetOperation);
342 READ_BOOL_FIELD(all);
343 READ_NODE_FIELD(larg);
344 READ_NODE_FIELD(rarg);
345 READ_NODE_FIELD(colTypes);
346 READ_NODE_FIELD(colTypmods);
347 READ_NODE_FIELD(colCollations);
348 READ_NODE_FIELD(groupClauses);
355 * Stuff from primnodes.h.
363 READ_STRING_FIELD(aliasname);
364 READ_NODE_FIELD(colnames);
372 READ_LOCALS(RangeVar);
374 local_node->catalogname = NULL; /* not currently saved in output
377 READ_STRING_FIELD(schemaname);
378 READ_STRING_FIELD(relname);
379 READ_ENUM_FIELD(inhOpt, InhOption);
380 READ_CHAR_FIELD(relpersistence);
381 READ_NODE_FIELD(alias);
382 READ_LOCATION_FIELD(location);
388 _readIntoClause(void)
390 READ_LOCALS(IntoClause);
392 READ_NODE_FIELD(rel);
393 READ_NODE_FIELD(colNames);
394 READ_NODE_FIELD(options);
395 READ_ENUM_FIELD(onCommit, OnCommitAction);
396 READ_STRING_FIELD(tableSpaceName);
409 READ_UINT_FIELD(varno);
410 READ_INT_FIELD(varattno);
411 READ_OID_FIELD(vartype);
412 READ_INT_FIELD(vartypmod);
413 READ_OID_FIELD(varcollid);
414 READ_UINT_FIELD(varlevelsup);
415 READ_UINT_FIELD(varnoold);
416 READ_INT_FIELD(varoattno);
417 READ_LOCATION_FIELD(location);
430 READ_OID_FIELD(consttype);
431 READ_INT_FIELD(consttypmod);
432 READ_OID_FIELD(constcollid);
433 READ_INT_FIELD(constlen);
434 READ_BOOL_FIELD(constbyval);
435 READ_BOOL_FIELD(constisnull);
436 READ_LOCATION_FIELD(location);
438 token = pg_strtok(&length); /* skip :constvalue */
439 if (local_node->constisnull)
440 token = pg_strtok(&length); /* skip "<>" */
442 local_node->constvalue = readDatum(local_node->constbyval);
455 READ_ENUM_FIELD(paramkind, ParamKind);
456 READ_INT_FIELD(paramid);
457 READ_OID_FIELD(paramtype);
458 READ_INT_FIELD(paramtypmod);
459 READ_OID_FIELD(paramcollid);
460 READ_LOCATION_FIELD(location);
473 READ_OID_FIELD(aggfnoid);
474 READ_OID_FIELD(aggtype);
475 READ_OID_FIELD(aggcollid);
476 READ_OID_FIELD(inputcollid);
477 READ_NODE_FIELD(args);
478 READ_NODE_FIELD(aggorder);
479 READ_NODE_FIELD(aggdistinct);
480 READ_BOOL_FIELD(aggstar);
481 READ_UINT_FIELD(agglevelsup);
482 READ_LOCATION_FIELD(location);
491 _readWindowFunc(void)
493 READ_LOCALS(WindowFunc);
495 READ_OID_FIELD(winfnoid);
496 READ_OID_FIELD(wintype);
497 READ_OID_FIELD(wincollid);
498 READ_OID_FIELD(inputcollid);
499 READ_NODE_FIELD(args);
500 READ_UINT_FIELD(winref);
501 READ_BOOL_FIELD(winstar);
502 READ_BOOL_FIELD(winagg);
503 READ_LOCATION_FIELD(location);
514 READ_LOCALS(ArrayRef);
516 READ_OID_FIELD(refarraytype);
517 READ_OID_FIELD(refelemtype);
518 READ_INT_FIELD(reftypmod);
519 READ_OID_FIELD(refcollid);
520 READ_NODE_FIELD(refupperindexpr);
521 READ_NODE_FIELD(reflowerindexpr);
522 READ_NODE_FIELD(refexpr);
523 READ_NODE_FIELD(refassgnexpr);
534 READ_LOCALS(FuncExpr);
536 READ_OID_FIELD(funcid);
537 READ_OID_FIELD(funcresulttype);
538 READ_BOOL_FIELD(funcretset);
539 READ_ENUM_FIELD(funcformat, CoercionForm);
540 READ_OID_FIELD(funccollid);
541 READ_OID_FIELD(inputcollid);
542 READ_NODE_FIELD(args);
543 READ_LOCATION_FIELD(location);
551 static NamedArgExpr *
552 _readNamedArgExpr(void)
554 READ_LOCALS(NamedArgExpr);
556 READ_NODE_FIELD(arg);
557 READ_STRING_FIELD(name);
558 READ_INT_FIELD(argnumber);
559 READ_LOCATION_FIELD(location);
572 READ_OID_FIELD(opno);
573 READ_OID_FIELD(opfuncid);
576 * The opfuncid is stored in the textual format primarily for debugging
577 * and documentation reasons. We want to always read it as zero to force
578 * it to be re-looked-up in the pg_operator entry. This ensures that
579 * stored rules don't have hidden dependencies on operators' functions.
580 * (We don't currently support an ALTER OPERATOR command, but might
583 local_node->opfuncid = InvalidOid;
585 READ_OID_FIELD(opresulttype);
586 READ_BOOL_FIELD(opretset);
587 READ_OID_FIELD(opcollid);
588 READ_OID_FIELD(inputcollid);
589 READ_NODE_FIELD(args);
590 READ_LOCATION_FIELD(location);
598 static DistinctExpr *
599 _readDistinctExpr(void)
601 READ_LOCALS(DistinctExpr);
603 READ_OID_FIELD(opno);
604 READ_OID_FIELD(opfuncid);
607 * The opfuncid is stored in the textual format primarily for debugging
608 * and documentation reasons. We want to always read it as zero to force
609 * it to be re-looked-up in the pg_operator entry. This ensures that
610 * stored rules don't have hidden dependencies on operators' functions.
611 * (We don't currently support an ALTER OPERATOR command, but might
614 local_node->opfuncid = InvalidOid;
616 READ_OID_FIELD(opresulttype);
617 READ_BOOL_FIELD(opretset);
618 READ_OID_FIELD(opcollid);
619 READ_OID_FIELD(inputcollid);
620 READ_NODE_FIELD(args);
621 READ_LOCATION_FIELD(location);
630 _readNullIfExpr(void)
632 READ_LOCALS(NullIfExpr);
634 READ_OID_FIELD(opno);
635 READ_OID_FIELD(opfuncid);
638 * The opfuncid is stored in the textual format primarily for debugging
639 * and documentation reasons. We want to always read it as zero to force
640 * it to be re-looked-up in the pg_operator entry. This ensures that
641 * stored rules don't have hidden dependencies on operators' functions.
642 * (We don't currently support an ALTER OPERATOR command, but might
645 local_node->opfuncid = InvalidOid;
647 READ_OID_FIELD(opresulttype);
648 READ_BOOL_FIELD(opretset);
649 READ_OID_FIELD(opcollid);
650 READ_OID_FIELD(inputcollid);
651 READ_NODE_FIELD(args);
652 READ_LOCATION_FIELD(location);
658 * _readScalarArrayOpExpr
660 static ScalarArrayOpExpr *
661 _readScalarArrayOpExpr(void)
663 READ_LOCALS(ScalarArrayOpExpr);
665 READ_OID_FIELD(opno);
666 READ_OID_FIELD(opfuncid);
669 * The opfuncid is stored in the textual format primarily for debugging
670 * and documentation reasons. We want to always read it as zero to force
671 * it to be re-looked-up in the pg_operator entry. This ensures that
672 * stored rules don't have hidden dependencies on operators' functions.
673 * (We don't currently support an ALTER OPERATOR command, but might
676 local_node->opfuncid = InvalidOid;
678 READ_BOOL_FIELD(useOr);
679 READ_OID_FIELD(inputcollid);
680 READ_NODE_FIELD(args);
681 READ_LOCATION_FIELD(location);
692 READ_LOCALS(BoolExpr);
694 /* do-it-yourself enum representation */
695 token = pg_strtok(&length); /* skip :boolop */
696 token = pg_strtok(&length); /* get field value */
697 if (strncmp(token, "and", 3) == 0)
698 local_node->boolop = AND_EXPR;
699 else if (strncmp(token, "or", 2) == 0)
700 local_node->boolop = OR_EXPR;
701 else if (strncmp(token, "not", 3) == 0)
702 local_node->boolop = NOT_EXPR;
704 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
706 READ_NODE_FIELD(args);
707 READ_LOCATION_FIELD(location);
718 READ_LOCALS(SubLink);
720 READ_ENUM_FIELD(subLinkType, SubLinkType);
721 READ_NODE_FIELD(testexpr);
722 READ_NODE_FIELD(operName);
723 READ_NODE_FIELD(subselect);
724 READ_LOCATION_FIELD(location);
730 * _readSubPlan is not needed since it doesn't appear in stored rules.
737 _readFieldSelect(void)
739 READ_LOCALS(FieldSelect);
741 READ_NODE_FIELD(arg);
742 READ_INT_FIELD(fieldnum);
743 READ_OID_FIELD(resulttype);
744 READ_INT_FIELD(resulttypmod);
745 READ_OID_FIELD(resultcollid);
754 _readFieldStore(void)
756 READ_LOCALS(FieldStore);
758 READ_NODE_FIELD(arg);
759 READ_NODE_FIELD(newvals);
760 READ_NODE_FIELD(fieldnums);
761 READ_OID_FIELD(resulttype);
770 _readRelabelType(void)
772 READ_LOCALS(RelabelType);
774 READ_NODE_FIELD(arg);
775 READ_OID_FIELD(resulttype);
776 READ_INT_FIELD(resulttypmod);
777 READ_OID_FIELD(resultcollid);
778 READ_ENUM_FIELD(relabelformat, CoercionForm);
779 READ_LOCATION_FIELD(location);
788 _readCoerceViaIO(void)
790 READ_LOCALS(CoerceViaIO);
792 READ_NODE_FIELD(arg);
793 READ_OID_FIELD(resulttype);
794 READ_OID_FIELD(resultcollid);
795 READ_ENUM_FIELD(coerceformat, CoercionForm);
796 READ_LOCATION_FIELD(location);
802 * _readArrayCoerceExpr
804 static ArrayCoerceExpr *
805 _readArrayCoerceExpr(void)
807 READ_LOCALS(ArrayCoerceExpr);
809 READ_NODE_FIELD(arg);
810 READ_OID_FIELD(elemfuncid);
811 READ_OID_FIELD(resulttype);
812 READ_INT_FIELD(resulttypmod);
813 READ_OID_FIELD(resultcollid);
814 READ_BOOL_FIELD(isExplicit);
815 READ_ENUM_FIELD(coerceformat, CoercionForm);
816 READ_LOCATION_FIELD(location);
822 * _readConvertRowtypeExpr
824 static ConvertRowtypeExpr *
825 _readConvertRowtypeExpr(void)
827 READ_LOCALS(ConvertRowtypeExpr);
829 READ_NODE_FIELD(arg);
830 READ_OID_FIELD(resulttype);
831 READ_ENUM_FIELD(convertformat, CoercionForm);
832 READ_LOCATION_FIELD(location);
841 _readCollateExpr(void)
843 READ_LOCALS(CollateExpr);
845 READ_NODE_FIELD(arg);
846 READ_OID_FIELD(collOid);
847 READ_LOCATION_FIELD(location);
858 READ_LOCALS(CaseExpr);
860 READ_OID_FIELD(casetype);
861 READ_OID_FIELD(casecollid);
862 READ_NODE_FIELD(arg);
863 READ_NODE_FIELD(args);
864 READ_NODE_FIELD(defresult);
865 READ_LOCATION_FIELD(location);
876 READ_LOCALS(CaseWhen);
878 READ_NODE_FIELD(expr);
879 READ_NODE_FIELD(result);
880 READ_LOCATION_FIELD(location);
888 static CaseTestExpr *
889 _readCaseTestExpr(void)
891 READ_LOCALS(CaseTestExpr);
893 READ_OID_FIELD(typeId);
894 READ_INT_FIELD(typeMod);
895 READ_OID_FIELD(collation);
906 READ_LOCALS(ArrayExpr);
908 READ_OID_FIELD(array_typeid);
909 READ_OID_FIELD(array_collid);
910 READ_OID_FIELD(element_typeid);
911 READ_NODE_FIELD(elements);
912 READ_BOOL_FIELD(multidims);
913 READ_LOCATION_FIELD(location);
924 READ_LOCALS(RowExpr);
926 READ_NODE_FIELD(args);
927 READ_OID_FIELD(row_typeid);
928 READ_ENUM_FIELD(row_format, CoercionForm);
929 READ_NODE_FIELD(colnames);
930 READ_LOCATION_FIELD(location);
936 * _readRowCompareExpr
938 static RowCompareExpr *
939 _readRowCompareExpr(void)
941 READ_LOCALS(RowCompareExpr);
943 READ_ENUM_FIELD(rctype, RowCompareType);
944 READ_NODE_FIELD(opnos);
945 READ_NODE_FIELD(opfamilies);
946 READ_NODE_FIELD(inputcollids);
947 READ_NODE_FIELD(largs);
948 READ_NODE_FIELD(rargs);
956 static CoalesceExpr *
957 _readCoalesceExpr(void)
959 READ_LOCALS(CoalesceExpr);
961 READ_OID_FIELD(coalescetype);
962 READ_OID_FIELD(coalescecollid);
963 READ_NODE_FIELD(args);
964 READ_LOCATION_FIELD(location);
973 _readMinMaxExpr(void)
975 READ_LOCALS(MinMaxExpr);
977 READ_OID_FIELD(minmaxtype);
978 READ_OID_FIELD(minmaxcollid);
979 READ_OID_FIELD(inputcollid);
980 READ_ENUM_FIELD(op, MinMaxOp);
981 READ_NODE_FIELD(args);
982 READ_LOCATION_FIELD(location);
993 READ_LOCALS(XmlExpr);
995 READ_ENUM_FIELD(op, XmlExprOp);
996 READ_STRING_FIELD(name);
997 READ_NODE_FIELD(named_args);
998 READ_NODE_FIELD(arg_names);
999 READ_NODE_FIELD(args);
1000 READ_ENUM_FIELD(xmloption, XmlOptionType);
1001 READ_OID_FIELD(type);
1002 READ_INT_FIELD(typmod);
1003 READ_LOCATION_FIELD(location);
1014 READ_LOCALS(NullTest);
1016 READ_NODE_FIELD(arg);
1017 READ_ENUM_FIELD(nulltesttype, NullTestType);
1018 READ_BOOL_FIELD(argisrow);
1026 static BooleanTest *
1027 _readBooleanTest(void)
1029 READ_LOCALS(BooleanTest);
1031 READ_NODE_FIELD(arg);
1032 READ_ENUM_FIELD(booltesttype, BoolTestType);
1038 * _readCoerceToDomain
1040 static CoerceToDomain *
1041 _readCoerceToDomain(void)
1043 READ_LOCALS(CoerceToDomain);
1045 READ_NODE_FIELD(arg);
1046 READ_OID_FIELD(resulttype);
1047 READ_INT_FIELD(resulttypmod);
1048 READ_OID_FIELD(resultcollid);
1049 READ_ENUM_FIELD(coercionformat, CoercionForm);
1050 READ_LOCATION_FIELD(location);
1056 * _readCoerceToDomainValue
1058 static CoerceToDomainValue *
1059 _readCoerceToDomainValue(void)
1061 READ_LOCALS(CoerceToDomainValue);
1063 READ_OID_FIELD(typeId);
1064 READ_INT_FIELD(typeMod);
1065 READ_OID_FIELD(collation);
1066 READ_LOCATION_FIELD(location);
1074 static SetToDefault *
1075 _readSetToDefault(void)
1077 READ_LOCALS(SetToDefault);
1079 READ_OID_FIELD(typeId);
1080 READ_INT_FIELD(typeMod);
1081 READ_OID_FIELD(collation);
1082 READ_LOCATION_FIELD(location);
1088 * _readCurrentOfExpr
1090 static CurrentOfExpr *
1091 _readCurrentOfExpr(void)
1093 READ_LOCALS(CurrentOfExpr);
1095 READ_UINT_FIELD(cvarno);
1096 READ_STRING_FIELD(cursor_name);
1097 READ_INT_FIELD(cursor_param);
1105 static TargetEntry *
1106 _readTargetEntry(void)
1108 READ_LOCALS(TargetEntry);
1110 READ_NODE_FIELD(expr);
1111 READ_INT_FIELD(resno);
1112 READ_STRING_FIELD(resname);
1113 READ_UINT_FIELD(ressortgroupref);
1114 READ_OID_FIELD(resorigtbl);
1115 READ_INT_FIELD(resorigcol);
1116 READ_BOOL_FIELD(resjunk);
1124 static RangeTblRef *
1125 _readRangeTblRef(void)
1127 READ_LOCALS(RangeTblRef);
1129 READ_INT_FIELD(rtindex);
1140 READ_LOCALS(JoinExpr);
1142 READ_ENUM_FIELD(jointype, JoinType);
1143 READ_BOOL_FIELD(isNatural);
1144 READ_NODE_FIELD(larg);
1145 READ_NODE_FIELD(rarg);
1146 READ_NODE_FIELD(usingClause);
1147 READ_NODE_FIELD(quals);
1148 READ_NODE_FIELD(alias);
1149 READ_INT_FIELD(rtindex);
1160 READ_LOCALS(FromExpr);
1162 READ_NODE_FIELD(fromlist);
1163 READ_NODE_FIELD(quals);
1170 * Stuff from parsenodes.h.
1174 * _readRangeTblEntry
1176 static RangeTblEntry *
1177 _readRangeTblEntry(void)
1179 READ_LOCALS(RangeTblEntry);
1181 /* put alias + eref first to make dump more legible */
1182 READ_NODE_FIELD(alias);
1183 READ_NODE_FIELD(eref);
1184 READ_ENUM_FIELD(rtekind, RTEKind);
1186 switch (local_node->rtekind)
1189 READ_OID_FIELD(relid);
1190 READ_CHAR_FIELD(relkind);
1193 READ_NODE_FIELD(subquery);
1196 READ_ENUM_FIELD(jointype, JoinType);
1197 READ_NODE_FIELD(joinaliasvars);
1200 READ_NODE_FIELD(funcexpr);
1201 READ_NODE_FIELD(funccoltypes);
1202 READ_NODE_FIELD(funccoltypmods);
1203 READ_NODE_FIELD(funccolcollations);
1206 READ_NODE_FIELD(values_lists);
1207 READ_NODE_FIELD(values_collations);
1210 READ_STRING_FIELD(ctename);
1211 READ_UINT_FIELD(ctelevelsup);
1212 READ_BOOL_FIELD(self_reference);
1213 READ_NODE_FIELD(ctecoltypes);
1214 READ_NODE_FIELD(ctecoltypmods);
1215 READ_NODE_FIELD(ctecolcollations);
1218 elog(ERROR, "unrecognized RTE kind: %d",
1219 (int) local_node->rtekind);
1223 READ_BOOL_FIELD(inh);
1224 READ_BOOL_FIELD(inFromCl);
1225 READ_UINT_FIELD(requiredPerms);
1226 READ_OID_FIELD(checkAsUser);
1227 READ_BITMAPSET_FIELD(selectedCols);
1228 READ_BITMAPSET_FIELD(modifiedCols);
1237 * Given a character string representing a node tree, parseNodeString creates
1238 * the internal node structure.
1240 * The string to be read must already have been loaded into pg_strtok().
1243 parseNodeString(void)
1249 token = pg_strtok(&length);
1251 #define MATCH(tokname, namelen) \
1252 (length == namelen && memcmp(token, tokname, namelen) == 0)
1254 if (MATCH("QUERY", 5))
1255 return_value = _readQuery();
1256 else if (MATCH("SORTGROUPCLAUSE", 15))
1257 return_value = _readSortGroupClause();
1258 else if (MATCH("WINDOWCLAUSE", 12))
1259 return_value = _readWindowClause();
1260 else if (MATCH("ROWMARKCLAUSE", 13))
1261 return_value = _readRowMarkClause();
1262 else if (MATCH("COMMONTABLEEXPR", 15))
1263 return_value = _readCommonTableExpr();
1264 else if (MATCH("SETOPERATIONSTMT", 16))
1265 return_value = _readSetOperationStmt();
1266 else if (MATCH("ALIAS", 5))
1267 return_value = _readAlias();
1268 else if (MATCH("RANGEVAR", 8))
1269 return_value = _readRangeVar();
1270 else if (MATCH("INTOCLAUSE", 10))
1271 return_value = _readIntoClause();
1272 else if (MATCH("VAR", 3))
1273 return_value = _readVar();
1274 else if (MATCH("CONST", 5))
1275 return_value = _readConst();
1276 else if (MATCH("PARAM", 5))
1277 return_value = _readParam();
1278 else if (MATCH("AGGREF", 6))
1279 return_value = _readAggref();
1280 else if (MATCH("WINDOWFUNC", 10))
1281 return_value = _readWindowFunc();
1282 else if (MATCH("ARRAYREF", 8))
1283 return_value = _readArrayRef();
1284 else if (MATCH("FUNCEXPR", 8))
1285 return_value = _readFuncExpr();
1286 else if (MATCH("NAMEDARGEXPR", 12))
1287 return_value = _readNamedArgExpr();
1288 else if (MATCH("OPEXPR", 6))
1289 return_value = _readOpExpr();
1290 else if (MATCH("DISTINCTEXPR", 12))
1291 return_value = _readDistinctExpr();
1292 else if (MATCH("NULLIFEXPR", 10))
1293 return_value = _readNullIfExpr();
1294 else if (MATCH("SCALARARRAYOPEXPR", 17))
1295 return_value = _readScalarArrayOpExpr();
1296 else if (MATCH("BOOLEXPR", 8))
1297 return_value = _readBoolExpr();
1298 else if (MATCH("SUBLINK", 7))
1299 return_value = _readSubLink();
1300 else if (MATCH("FIELDSELECT", 11))
1301 return_value = _readFieldSelect();
1302 else if (MATCH("FIELDSTORE", 10))
1303 return_value = _readFieldStore();
1304 else if (MATCH("RELABELTYPE", 11))
1305 return_value = _readRelabelType();
1306 else if (MATCH("COERCEVIAIO", 11))
1307 return_value = _readCoerceViaIO();
1308 else if (MATCH("ARRAYCOERCEEXPR", 15))
1309 return_value = _readArrayCoerceExpr();
1310 else if (MATCH("CONVERTROWTYPEEXPR", 18))
1311 return_value = _readConvertRowtypeExpr();
1312 else if (MATCH("COLLATE", 7))
1313 return_value = _readCollateExpr();
1314 else if (MATCH("CASE", 4))
1315 return_value = _readCaseExpr();
1316 else if (MATCH("WHEN", 4))
1317 return_value = _readCaseWhen();
1318 else if (MATCH("CASETESTEXPR", 12))
1319 return_value = _readCaseTestExpr();
1320 else if (MATCH("ARRAY", 5))
1321 return_value = _readArrayExpr();
1322 else if (MATCH("ROW", 3))
1323 return_value = _readRowExpr();
1324 else if (MATCH("ROWCOMPARE", 10))
1325 return_value = _readRowCompareExpr();
1326 else if (MATCH("COALESCE", 8))
1327 return_value = _readCoalesceExpr();
1328 else if (MATCH("MINMAX", 6))
1329 return_value = _readMinMaxExpr();
1330 else if (MATCH("XMLEXPR", 7))
1331 return_value = _readXmlExpr();
1332 else if (MATCH("NULLTEST", 8))
1333 return_value = _readNullTest();
1334 else if (MATCH("BOOLEANTEST", 11))
1335 return_value = _readBooleanTest();
1336 else if (MATCH("COERCETODOMAIN", 14))
1337 return_value = _readCoerceToDomain();
1338 else if (MATCH("COERCETODOMAINVALUE", 19))
1339 return_value = _readCoerceToDomainValue();
1340 else if (MATCH("SETTODEFAULT", 12))
1341 return_value = _readSetToDefault();
1342 else if (MATCH("CURRENTOFEXPR", 13))
1343 return_value = _readCurrentOfExpr();
1344 else if (MATCH("TARGETENTRY", 11))
1345 return_value = _readTargetEntry();
1346 else if (MATCH("RANGETBLREF", 11))
1347 return_value = _readRangeTblRef();
1348 else if (MATCH("JOINEXPR", 8))
1349 return_value = _readJoinExpr();
1350 else if (MATCH("FROMEXPR", 8))
1351 return_value = _readFromExpr();
1352 else if (MATCH("RTE", 3))
1353 return_value = _readRangeTblEntry();
1354 else if (MATCH("NOTIFY", 6))
1355 return_value = _readNotifyStmt();
1356 else if (MATCH("DECLARECURSOR", 13))
1357 return_value = _readDeclareCursorStmt();
1360 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
1361 return_value = NULL; /* keep compiler quiet */
1364 return (Node *) return_value;
1371 * Given a string representation of a constant, recreate the appropriate
1372 * Datum. The string representation embeds length info, but not byValue,
1373 * so we must be told that.
1376 readDatum(bool typbyval)
1386 * read the actual length of the value
1388 token = pg_strtok(&tokenLength);
1389 length = atoui(token);
1391 token = pg_strtok(&tokenLength); /* read the '[' */
1392 if (token == NULL || token[0] != '[')
1393 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu",
1394 token ? (const char *) token : "[NULL]",
1395 (unsigned long) length);
1399 if (length > (Size) sizeof(Datum))
1400 elog(ERROR, "byval datum but length = %lu",
1401 (unsigned long) length);
1403 s = (char *) (&res);
1404 for (i = 0; i < (Size) sizeof(Datum); i++)
1406 token = pg_strtok(&tokenLength);
1407 s[i] = (char) atoi(token);
1410 else if (length <= 0)
1414 s = (char *) palloc(length);
1415 for (i = 0; i < length; i++)
1417 token = pg_strtok(&tokenLength);
1418 s[i] = (char) atoi(token);
1420 res = PointerGetDatum(s);
1423 token = pg_strtok(&tokenLength); /* read the ']' */
1424 if (token == NULL || token[0] != ']')
1425 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu",
1426 token ? (const char *) token : "[NULL]",
1427 (unsigned long) length);