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(aggdirectargs);
496 READ_NODE_FIELD(args);
497 READ_NODE_FIELD(aggorder);
498 READ_NODE_FIELD(aggdistinct);
499 READ_NODE_FIELD(aggfilter);
500 READ_BOOL_FIELD(aggstar);
501 READ_BOOL_FIELD(aggvariadic);
502 READ_CHAR_FIELD(aggkind);
503 READ_UINT_FIELD(agglevelsup);
504 READ_LOCATION_FIELD(location);
513 _readWindowFunc(void)
515 READ_LOCALS(WindowFunc);
517 READ_OID_FIELD(winfnoid);
518 READ_OID_FIELD(wintype);
519 READ_OID_FIELD(wincollid);
520 READ_OID_FIELD(inputcollid);
521 READ_NODE_FIELD(args);
522 READ_NODE_FIELD(aggfilter);
523 READ_UINT_FIELD(winref);
524 READ_BOOL_FIELD(winstar);
525 READ_BOOL_FIELD(winagg);
526 READ_LOCATION_FIELD(location);
537 READ_LOCALS(ArrayRef);
539 READ_OID_FIELD(refarraytype);
540 READ_OID_FIELD(refelemtype);
541 READ_INT_FIELD(reftypmod);
542 READ_OID_FIELD(refcollid);
543 READ_NODE_FIELD(refupperindexpr);
544 READ_NODE_FIELD(reflowerindexpr);
545 READ_NODE_FIELD(refexpr);
546 READ_NODE_FIELD(refassgnexpr);
557 READ_LOCALS(FuncExpr);
559 READ_OID_FIELD(funcid);
560 READ_OID_FIELD(funcresulttype);
561 READ_BOOL_FIELD(funcretset);
562 READ_BOOL_FIELD(funcvariadic);
563 READ_ENUM_FIELD(funcformat, CoercionForm);
564 READ_OID_FIELD(funccollid);
565 READ_OID_FIELD(inputcollid);
566 READ_NODE_FIELD(args);
567 READ_LOCATION_FIELD(location);
575 static NamedArgExpr *
576 _readNamedArgExpr(void)
578 READ_LOCALS(NamedArgExpr);
580 READ_NODE_FIELD(arg);
581 READ_STRING_FIELD(name);
582 READ_INT_FIELD(argnumber);
583 READ_LOCATION_FIELD(location);
596 READ_OID_FIELD(opno);
597 READ_OID_FIELD(opfuncid);
600 * The opfuncid is stored in the textual format primarily for debugging
601 * and documentation reasons. We want to always read it as zero to force
602 * it to be re-looked-up in the pg_operator entry. This ensures that
603 * stored rules don't have hidden dependencies on operators' functions.
604 * (We don't currently support an ALTER OPERATOR command, but might
607 local_node->opfuncid = InvalidOid;
609 READ_OID_FIELD(opresulttype);
610 READ_BOOL_FIELD(opretset);
611 READ_OID_FIELD(opcollid);
612 READ_OID_FIELD(inputcollid);
613 READ_NODE_FIELD(args);
614 READ_LOCATION_FIELD(location);
622 static DistinctExpr *
623 _readDistinctExpr(void)
625 READ_LOCALS(DistinctExpr);
627 READ_OID_FIELD(opno);
628 READ_OID_FIELD(opfuncid);
631 * The opfuncid is stored in the textual format primarily for debugging
632 * and documentation reasons. We want to always read it as zero to force
633 * it to be re-looked-up in the pg_operator entry. This ensures that
634 * stored rules don't have hidden dependencies on operators' functions.
635 * (We don't currently support an ALTER OPERATOR command, but might
638 local_node->opfuncid = InvalidOid;
640 READ_OID_FIELD(opresulttype);
641 READ_BOOL_FIELD(opretset);
642 READ_OID_FIELD(opcollid);
643 READ_OID_FIELD(inputcollid);
644 READ_NODE_FIELD(args);
645 READ_LOCATION_FIELD(location);
654 _readNullIfExpr(void)
656 READ_LOCALS(NullIfExpr);
658 READ_OID_FIELD(opno);
659 READ_OID_FIELD(opfuncid);
662 * The opfuncid is stored in the textual format primarily for debugging
663 * and documentation reasons. We want to always read it as zero to force
664 * it to be re-looked-up in the pg_operator entry. This ensures that
665 * stored rules don't have hidden dependencies on operators' functions.
666 * (We don't currently support an ALTER OPERATOR command, but might
669 local_node->opfuncid = InvalidOid;
671 READ_OID_FIELD(opresulttype);
672 READ_BOOL_FIELD(opretset);
673 READ_OID_FIELD(opcollid);
674 READ_OID_FIELD(inputcollid);
675 READ_NODE_FIELD(args);
676 READ_LOCATION_FIELD(location);
682 * _readScalarArrayOpExpr
684 static ScalarArrayOpExpr *
685 _readScalarArrayOpExpr(void)
687 READ_LOCALS(ScalarArrayOpExpr);
689 READ_OID_FIELD(opno);
690 READ_OID_FIELD(opfuncid);
693 * The opfuncid is stored in the textual format primarily for debugging
694 * and documentation reasons. We want to always read it as zero to force
695 * it to be re-looked-up in the pg_operator entry. This ensures that
696 * stored rules don't have hidden dependencies on operators' functions.
697 * (We don't currently support an ALTER OPERATOR command, but might
700 local_node->opfuncid = InvalidOid;
702 READ_BOOL_FIELD(useOr);
703 READ_OID_FIELD(inputcollid);
704 READ_NODE_FIELD(args);
705 READ_LOCATION_FIELD(location);
716 READ_LOCALS(BoolExpr);
718 /* do-it-yourself enum representation */
719 token = pg_strtok(&length); /* skip :boolop */
720 token = pg_strtok(&length); /* get field value */
721 if (strncmp(token, "and", 3) == 0)
722 local_node->boolop = AND_EXPR;
723 else if (strncmp(token, "or", 2) == 0)
724 local_node->boolop = OR_EXPR;
725 else if (strncmp(token, "not", 3) == 0)
726 local_node->boolop = NOT_EXPR;
728 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
730 READ_NODE_FIELD(args);
731 READ_LOCATION_FIELD(location);
742 READ_LOCALS(SubLink);
744 READ_ENUM_FIELD(subLinkType, SubLinkType);
745 READ_NODE_FIELD(testexpr);
746 READ_NODE_FIELD(operName);
747 READ_NODE_FIELD(subselect);
748 READ_LOCATION_FIELD(location);
754 * _readSubPlan is not needed since it doesn't appear in stored rules.
761 _readFieldSelect(void)
763 READ_LOCALS(FieldSelect);
765 READ_NODE_FIELD(arg);
766 READ_INT_FIELD(fieldnum);
767 READ_OID_FIELD(resulttype);
768 READ_INT_FIELD(resulttypmod);
769 READ_OID_FIELD(resultcollid);
778 _readFieldStore(void)
780 READ_LOCALS(FieldStore);
782 READ_NODE_FIELD(arg);
783 READ_NODE_FIELD(newvals);
784 READ_NODE_FIELD(fieldnums);
785 READ_OID_FIELD(resulttype);
794 _readRelabelType(void)
796 READ_LOCALS(RelabelType);
798 READ_NODE_FIELD(arg);
799 READ_OID_FIELD(resulttype);
800 READ_INT_FIELD(resulttypmod);
801 READ_OID_FIELD(resultcollid);
802 READ_ENUM_FIELD(relabelformat, CoercionForm);
803 READ_LOCATION_FIELD(location);
812 _readCoerceViaIO(void)
814 READ_LOCALS(CoerceViaIO);
816 READ_NODE_FIELD(arg);
817 READ_OID_FIELD(resulttype);
818 READ_OID_FIELD(resultcollid);
819 READ_ENUM_FIELD(coerceformat, CoercionForm);
820 READ_LOCATION_FIELD(location);
826 * _readArrayCoerceExpr
828 static ArrayCoerceExpr *
829 _readArrayCoerceExpr(void)
831 READ_LOCALS(ArrayCoerceExpr);
833 READ_NODE_FIELD(arg);
834 READ_OID_FIELD(elemfuncid);
835 READ_OID_FIELD(resulttype);
836 READ_INT_FIELD(resulttypmod);
837 READ_OID_FIELD(resultcollid);
838 READ_BOOL_FIELD(isExplicit);
839 READ_ENUM_FIELD(coerceformat, CoercionForm);
840 READ_LOCATION_FIELD(location);
846 * _readConvertRowtypeExpr
848 static ConvertRowtypeExpr *
849 _readConvertRowtypeExpr(void)
851 READ_LOCALS(ConvertRowtypeExpr);
853 READ_NODE_FIELD(arg);
854 READ_OID_FIELD(resulttype);
855 READ_ENUM_FIELD(convertformat, CoercionForm);
856 READ_LOCATION_FIELD(location);
865 _readCollateExpr(void)
867 READ_LOCALS(CollateExpr);
869 READ_NODE_FIELD(arg);
870 READ_OID_FIELD(collOid);
871 READ_LOCATION_FIELD(location);
882 READ_LOCALS(CaseExpr);
884 READ_OID_FIELD(casetype);
885 READ_OID_FIELD(casecollid);
886 READ_NODE_FIELD(arg);
887 READ_NODE_FIELD(args);
888 READ_NODE_FIELD(defresult);
889 READ_LOCATION_FIELD(location);
900 READ_LOCALS(CaseWhen);
902 READ_NODE_FIELD(expr);
903 READ_NODE_FIELD(result);
904 READ_LOCATION_FIELD(location);
912 static CaseTestExpr *
913 _readCaseTestExpr(void)
915 READ_LOCALS(CaseTestExpr);
917 READ_OID_FIELD(typeId);
918 READ_INT_FIELD(typeMod);
919 READ_OID_FIELD(collation);
930 READ_LOCALS(ArrayExpr);
932 READ_OID_FIELD(array_typeid);
933 READ_OID_FIELD(array_collid);
934 READ_OID_FIELD(element_typeid);
935 READ_NODE_FIELD(elements);
936 READ_BOOL_FIELD(multidims);
937 READ_LOCATION_FIELD(location);
948 READ_LOCALS(RowExpr);
950 READ_NODE_FIELD(args);
951 READ_OID_FIELD(row_typeid);
952 READ_ENUM_FIELD(row_format, CoercionForm);
953 READ_NODE_FIELD(colnames);
954 READ_LOCATION_FIELD(location);
960 * _readRowCompareExpr
962 static RowCompareExpr *
963 _readRowCompareExpr(void)
965 READ_LOCALS(RowCompareExpr);
967 READ_ENUM_FIELD(rctype, RowCompareType);
968 READ_NODE_FIELD(opnos);
969 READ_NODE_FIELD(opfamilies);
970 READ_NODE_FIELD(inputcollids);
971 READ_NODE_FIELD(largs);
972 READ_NODE_FIELD(rargs);
980 static CoalesceExpr *
981 _readCoalesceExpr(void)
983 READ_LOCALS(CoalesceExpr);
985 READ_OID_FIELD(coalescetype);
986 READ_OID_FIELD(coalescecollid);
987 READ_NODE_FIELD(args);
988 READ_LOCATION_FIELD(location);
997 _readMinMaxExpr(void)
999 READ_LOCALS(MinMaxExpr);
1001 READ_OID_FIELD(minmaxtype);
1002 READ_OID_FIELD(minmaxcollid);
1003 READ_OID_FIELD(inputcollid);
1004 READ_ENUM_FIELD(op, MinMaxOp);
1005 READ_NODE_FIELD(args);
1006 READ_LOCATION_FIELD(location);
1017 READ_LOCALS(XmlExpr);
1019 READ_ENUM_FIELD(op, XmlExprOp);
1020 READ_STRING_FIELD(name);
1021 READ_NODE_FIELD(named_args);
1022 READ_NODE_FIELD(arg_names);
1023 READ_NODE_FIELD(args);
1024 READ_ENUM_FIELD(xmloption, XmlOptionType);
1025 READ_OID_FIELD(type);
1026 READ_INT_FIELD(typmod);
1027 READ_LOCATION_FIELD(location);
1038 READ_LOCALS(NullTest);
1040 READ_NODE_FIELD(arg);
1041 READ_ENUM_FIELD(nulltesttype, NullTestType);
1042 READ_BOOL_FIELD(argisrow);
1050 static BooleanTest *
1051 _readBooleanTest(void)
1053 READ_LOCALS(BooleanTest);
1055 READ_NODE_FIELD(arg);
1056 READ_ENUM_FIELD(booltesttype, BoolTestType);
1062 * _readCoerceToDomain
1064 static CoerceToDomain *
1065 _readCoerceToDomain(void)
1067 READ_LOCALS(CoerceToDomain);
1069 READ_NODE_FIELD(arg);
1070 READ_OID_FIELD(resulttype);
1071 READ_INT_FIELD(resulttypmod);
1072 READ_OID_FIELD(resultcollid);
1073 READ_ENUM_FIELD(coercionformat, CoercionForm);
1074 READ_LOCATION_FIELD(location);
1080 * _readCoerceToDomainValue
1082 static CoerceToDomainValue *
1083 _readCoerceToDomainValue(void)
1085 READ_LOCALS(CoerceToDomainValue);
1087 READ_OID_FIELD(typeId);
1088 READ_INT_FIELD(typeMod);
1089 READ_OID_FIELD(collation);
1090 READ_LOCATION_FIELD(location);
1098 static SetToDefault *
1099 _readSetToDefault(void)
1101 READ_LOCALS(SetToDefault);
1103 READ_OID_FIELD(typeId);
1104 READ_INT_FIELD(typeMod);
1105 READ_OID_FIELD(collation);
1106 READ_LOCATION_FIELD(location);
1112 * _readCurrentOfExpr
1114 static CurrentOfExpr *
1115 _readCurrentOfExpr(void)
1117 READ_LOCALS(CurrentOfExpr);
1119 READ_UINT_FIELD(cvarno);
1120 READ_STRING_FIELD(cursor_name);
1121 READ_INT_FIELD(cursor_param);
1129 static TargetEntry *
1130 _readTargetEntry(void)
1132 READ_LOCALS(TargetEntry);
1134 READ_NODE_FIELD(expr);
1135 READ_INT_FIELD(resno);
1136 READ_STRING_FIELD(resname);
1137 READ_UINT_FIELD(ressortgroupref);
1138 READ_OID_FIELD(resorigtbl);
1139 READ_INT_FIELD(resorigcol);
1140 READ_BOOL_FIELD(resjunk);
1148 static RangeTblRef *
1149 _readRangeTblRef(void)
1151 READ_LOCALS(RangeTblRef);
1153 READ_INT_FIELD(rtindex);
1164 READ_LOCALS(JoinExpr);
1166 READ_ENUM_FIELD(jointype, JoinType);
1167 READ_BOOL_FIELD(isNatural);
1168 READ_NODE_FIELD(larg);
1169 READ_NODE_FIELD(rarg);
1170 READ_NODE_FIELD(usingClause);
1171 READ_NODE_FIELD(quals);
1172 READ_NODE_FIELD(alias);
1173 READ_INT_FIELD(rtindex);
1184 READ_LOCALS(FromExpr);
1186 READ_NODE_FIELD(fromlist);
1187 READ_NODE_FIELD(quals);
1194 * Stuff from parsenodes.h.
1198 * _readRangeTblEntry
1200 static RangeTblEntry *
1201 _readRangeTblEntry(void)
1203 READ_LOCALS(RangeTblEntry);
1205 /* put alias + eref first to make dump more legible */
1206 READ_NODE_FIELD(alias);
1207 READ_NODE_FIELD(eref);
1208 READ_ENUM_FIELD(rtekind, RTEKind);
1210 switch (local_node->rtekind)
1213 READ_OID_FIELD(relid);
1214 READ_CHAR_FIELD(relkind);
1217 READ_NODE_FIELD(subquery);
1218 READ_BOOL_FIELD(security_barrier);
1221 READ_ENUM_FIELD(jointype, JoinType);
1222 READ_NODE_FIELD(joinaliasvars);
1225 READ_NODE_FIELD(functions);
1226 READ_BOOL_FIELD(funcordinality);
1229 READ_NODE_FIELD(values_lists);
1230 READ_NODE_FIELD(values_collations);
1233 READ_STRING_FIELD(ctename);
1234 READ_UINT_FIELD(ctelevelsup);
1235 READ_BOOL_FIELD(self_reference);
1236 READ_NODE_FIELD(ctecoltypes);
1237 READ_NODE_FIELD(ctecoltypmods);
1238 READ_NODE_FIELD(ctecolcollations);
1241 elog(ERROR, "unrecognized RTE kind: %d",
1242 (int) local_node->rtekind);
1246 READ_BOOL_FIELD(lateral);
1247 READ_BOOL_FIELD(inh);
1248 READ_BOOL_FIELD(inFromCl);
1249 READ_UINT_FIELD(requiredPerms);
1250 READ_OID_FIELD(checkAsUser);
1251 READ_BITMAPSET_FIELD(selectedCols);
1252 READ_BITMAPSET_FIELD(modifiedCols);
1258 * _readRangeTblFunction
1260 static RangeTblFunction *
1261 _readRangeTblFunction(void)
1263 READ_LOCALS(RangeTblFunction);
1265 READ_NODE_FIELD(funcexpr);
1266 READ_INT_FIELD(funccolcount);
1267 READ_NODE_FIELD(funccolnames);
1268 READ_NODE_FIELD(funccoltypes);
1269 READ_NODE_FIELD(funccoltypmods);
1270 READ_NODE_FIELD(funccolcollations);
1271 READ_BITMAPSET_FIELD(funcparams);
1280 * Given a character string representing a node tree, parseNodeString creates
1281 * the internal node structure.
1283 * The string to be read must already have been loaded into pg_strtok().
1286 parseNodeString(void)
1292 token = pg_strtok(&length);
1294 #define MATCH(tokname, namelen) \
1295 (length == namelen && memcmp(token, tokname, namelen) == 0)
1297 if (MATCH("QUERY", 5))
1298 return_value = _readQuery();
1299 else if (MATCH("WITHCHECKOPTION", 15))
1300 return_value = _readWithCheckOption();
1301 else if (MATCH("SORTGROUPCLAUSE", 15))
1302 return_value = _readSortGroupClause();
1303 else if (MATCH("WINDOWCLAUSE", 12))
1304 return_value = _readWindowClause();
1305 else if (MATCH("ROWMARKCLAUSE", 13))
1306 return_value = _readRowMarkClause();
1307 else if (MATCH("COMMONTABLEEXPR", 15))
1308 return_value = _readCommonTableExpr();
1309 else if (MATCH("SETOPERATIONSTMT", 16))
1310 return_value = _readSetOperationStmt();
1311 else if (MATCH("ALIAS", 5))
1312 return_value = _readAlias();
1313 else if (MATCH("RANGEVAR", 8))
1314 return_value = _readRangeVar();
1315 else if (MATCH("INTOCLAUSE", 10))
1316 return_value = _readIntoClause();
1317 else if (MATCH("VAR", 3))
1318 return_value = _readVar();
1319 else if (MATCH("CONST", 5))
1320 return_value = _readConst();
1321 else if (MATCH("PARAM", 5))
1322 return_value = _readParam();
1323 else if (MATCH("AGGREF", 6))
1324 return_value = _readAggref();
1325 else if (MATCH("WINDOWFUNC", 10))
1326 return_value = _readWindowFunc();
1327 else if (MATCH("ARRAYREF", 8))
1328 return_value = _readArrayRef();
1329 else if (MATCH("FUNCEXPR", 8))
1330 return_value = _readFuncExpr();
1331 else if (MATCH("NAMEDARGEXPR", 12))
1332 return_value = _readNamedArgExpr();
1333 else if (MATCH("OPEXPR", 6))
1334 return_value = _readOpExpr();
1335 else if (MATCH("DISTINCTEXPR", 12))
1336 return_value = _readDistinctExpr();
1337 else if (MATCH("NULLIFEXPR", 10))
1338 return_value = _readNullIfExpr();
1339 else if (MATCH("SCALARARRAYOPEXPR", 17))
1340 return_value = _readScalarArrayOpExpr();
1341 else if (MATCH("BOOLEXPR", 8))
1342 return_value = _readBoolExpr();
1343 else if (MATCH("SUBLINK", 7))
1344 return_value = _readSubLink();
1345 else if (MATCH("FIELDSELECT", 11))
1346 return_value = _readFieldSelect();
1347 else if (MATCH("FIELDSTORE", 10))
1348 return_value = _readFieldStore();
1349 else if (MATCH("RELABELTYPE", 11))
1350 return_value = _readRelabelType();
1351 else if (MATCH("COERCEVIAIO", 11))
1352 return_value = _readCoerceViaIO();
1353 else if (MATCH("ARRAYCOERCEEXPR", 15))
1354 return_value = _readArrayCoerceExpr();
1355 else if (MATCH("CONVERTROWTYPEEXPR", 18))
1356 return_value = _readConvertRowtypeExpr();
1357 else if (MATCH("COLLATE", 7))
1358 return_value = _readCollateExpr();
1359 else if (MATCH("CASE", 4))
1360 return_value = _readCaseExpr();
1361 else if (MATCH("WHEN", 4))
1362 return_value = _readCaseWhen();
1363 else if (MATCH("CASETESTEXPR", 12))
1364 return_value = _readCaseTestExpr();
1365 else if (MATCH("ARRAY", 5))
1366 return_value = _readArrayExpr();
1367 else if (MATCH("ROW", 3))
1368 return_value = _readRowExpr();
1369 else if (MATCH("ROWCOMPARE", 10))
1370 return_value = _readRowCompareExpr();
1371 else if (MATCH("COALESCE", 8))
1372 return_value = _readCoalesceExpr();
1373 else if (MATCH("MINMAX", 6))
1374 return_value = _readMinMaxExpr();
1375 else if (MATCH("XMLEXPR", 7))
1376 return_value = _readXmlExpr();
1377 else if (MATCH("NULLTEST", 8))
1378 return_value = _readNullTest();
1379 else if (MATCH("BOOLEANTEST", 11))
1380 return_value = _readBooleanTest();
1381 else if (MATCH("COERCETODOMAIN", 14))
1382 return_value = _readCoerceToDomain();
1383 else if (MATCH("COERCETODOMAINVALUE", 19))
1384 return_value = _readCoerceToDomainValue();
1385 else if (MATCH("SETTODEFAULT", 12))
1386 return_value = _readSetToDefault();
1387 else if (MATCH("CURRENTOFEXPR", 13))
1388 return_value = _readCurrentOfExpr();
1389 else if (MATCH("TARGETENTRY", 11))
1390 return_value = _readTargetEntry();
1391 else if (MATCH("RANGETBLREF", 11))
1392 return_value = _readRangeTblRef();
1393 else if (MATCH("JOINEXPR", 8))
1394 return_value = _readJoinExpr();
1395 else if (MATCH("FROMEXPR", 8))
1396 return_value = _readFromExpr();
1397 else if (MATCH("RTE", 3))
1398 return_value = _readRangeTblEntry();
1399 else if (MATCH("RANGETBLFUNCTION", 16))
1400 return_value = _readRangeTblFunction();
1401 else if (MATCH("NOTIFY", 6))
1402 return_value = _readNotifyStmt();
1403 else if (MATCH("DECLARECURSOR", 13))
1404 return_value = _readDeclareCursorStmt();
1407 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
1408 return_value = NULL; /* keep compiler quiet */
1411 return (Node *) return_value;
1418 * Given a string representation of a constant, recreate the appropriate
1419 * Datum. The string representation embeds length info, but not byValue,
1420 * so we must be told that.
1423 readDatum(bool typbyval)
1433 * read the actual length of the value
1435 token = pg_strtok(&tokenLength);
1436 length = atoui(token);
1438 token = pg_strtok(&tokenLength); /* read the '[' */
1439 if (token == NULL || token[0] != '[')
1440 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu",
1441 token ? (const char *) token : "[NULL]",
1442 (unsigned long) length);
1446 if (length > (Size) sizeof(Datum))
1447 elog(ERROR, "byval datum but length = %lu",
1448 (unsigned long) length);
1450 s = (char *) (&res);
1451 for (i = 0; i < (Size) sizeof(Datum); i++)
1453 token = pg_strtok(&tokenLength);
1454 s[i] = (char) atoi(token);
1457 else if (length <= 0)
1461 s = (char *) palloc(length);
1462 for (i = 0; i < length; i++)
1464 token = pg_strtok(&tokenLength);
1465 s[i] = (char) atoi(token);
1467 res = PointerGetDatum(s);
1470 token = pg_strtok(&tokenLength); /* read the ']' */
1471 if (token == NULL || token[0] != ']')
1472 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu",
1473 token ? (const char *) token : "[NULL]",
1474 (unsigned long) length);