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() \
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 local_node->fldname = nodeRead(NULL, 0)
117 /* Read a bitmapset field */
118 #define READ_BITMAPSET_FIELD(fldname) \
119 token = pg_strtok(&length); /* skip :fldname */ \
120 local_node->fldname = _readBitmapset()
123 #define READ_DONE() \
128 * NOTE: use atoi() to read values written with %d, or atoui() to read
129 * values written with %u in outfuncs.c. An exception is OID values,
130 * for which use atooid(). (As of 7.1, outfuncs.c writes OIDs as %u,
131 * but this will probably change in the future.)
133 #define atoui(x) ((unsigned int) strtoul((x), NULL, 10))
135 #define atooid(x) ((Oid) strtoul((x), NULL, 10))
137 #define strtobool(x) ((*(x) == 't') ? true : false)
139 #define nullable_string(token,length) \
140 ((length) == 0 ? NULL : debackslash(token, length))
143 static Datum readDatum(bool typbyval);
151 Bitmapset *result = NULL;
155 token = pg_strtok(&length);
157 elog(ERROR, "incomplete Bitmapset structure");
158 if (length != 1 || token[0] != '(')
159 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
161 token = pg_strtok(&length);
163 elog(ERROR, "incomplete Bitmapset structure");
164 if (length != 1 || token[0] != 'b')
165 elog(ERROR, "unrecognized token: \"%.*s\"", length, token);
172 token = pg_strtok(&length);
174 elog(ERROR, "unterminated Bitmapset structure");
175 if (length == 1 && token[0] == ')')
177 val = (int) strtol(token, &endptr, 10);
178 if (endptr != token + length)
179 elog(ERROR, "unrecognized integer: \"%.*s\"", length, token);
180 result = bms_add_member(result, val);
195 READ_ENUM_FIELD(commandType, CmdType);
196 READ_ENUM_FIELD(querySource, QuerySource);
197 READ_BOOL_FIELD(canSetTag);
198 READ_NODE_FIELD(utilityStmt);
199 READ_INT_FIELD(resultRelation);
200 READ_NODE_FIELD(intoClause);
201 READ_BOOL_FIELD(hasAggs);
202 READ_BOOL_FIELD(hasWindowFuncs);
203 READ_BOOL_FIELD(hasSubLinks);
204 READ_BOOL_FIELD(hasDistinctOn);
205 READ_BOOL_FIELD(hasRecursive);
206 READ_BOOL_FIELD(hasModifyingCTE);
207 READ_BOOL_FIELD(hasForUpdate);
208 READ_NODE_FIELD(cteList);
209 READ_NODE_FIELD(rtable);
210 READ_NODE_FIELD(jointree);
211 READ_NODE_FIELD(targetList);
212 READ_NODE_FIELD(returningList);
213 READ_NODE_FIELD(groupClause);
214 READ_NODE_FIELD(havingQual);
215 READ_NODE_FIELD(windowClause);
216 READ_NODE_FIELD(distinctClause);
217 READ_NODE_FIELD(sortClause);
218 READ_NODE_FIELD(limitOffset);
219 READ_NODE_FIELD(limitCount);
220 READ_NODE_FIELD(rowMarks);
221 READ_NODE_FIELD(setOperations);
222 READ_NODE_FIELD(constraintDeps);
231 _readNotifyStmt(void)
233 READ_LOCALS(NotifyStmt);
235 READ_STRING_FIELD(conditionname);
236 READ_STRING_FIELD(payload);
242 * _readDeclareCursorStmt
244 static DeclareCursorStmt *
245 _readDeclareCursorStmt(void)
247 READ_LOCALS(DeclareCursorStmt);
249 READ_STRING_FIELD(portalname);
250 READ_INT_FIELD(options);
251 READ_NODE_FIELD(query);
257 * _readSortGroupClause
259 static SortGroupClause *
260 _readSortGroupClause(void)
262 READ_LOCALS(SortGroupClause);
264 READ_UINT_FIELD(tleSortGroupRef);
265 READ_OID_FIELD(eqop);
266 READ_OID_FIELD(sortop);
267 READ_BOOL_FIELD(nulls_first);
268 READ_BOOL_FIELD(hashable);
276 static WindowClause *
277 _readWindowClause(void)
279 READ_LOCALS(WindowClause);
281 READ_STRING_FIELD(name);
282 READ_STRING_FIELD(refname);
283 READ_NODE_FIELD(partitionClause);
284 READ_NODE_FIELD(orderClause);
285 READ_INT_FIELD(frameOptions);
286 READ_NODE_FIELD(startOffset);
287 READ_NODE_FIELD(endOffset);
288 READ_UINT_FIELD(winref);
289 READ_BOOL_FIELD(copiedOrder);
297 static RowMarkClause *
298 _readRowMarkClause(void)
300 READ_LOCALS(RowMarkClause);
302 READ_UINT_FIELD(rti);
303 READ_BOOL_FIELD(forUpdate);
304 READ_BOOL_FIELD(noWait);
305 READ_BOOL_FIELD(pushedDown);
311 * _readCommonTableExpr
313 static CommonTableExpr *
314 _readCommonTableExpr(void)
316 READ_LOCALS(CommonTableExpr);
318 READ_STRING_FIELD(ctename);
319 READ_NODE_FIELD(aliascolnames);
320 READ_NODE_FIELD(ctequery);
321 READ_LOCATION_FIELD(location);
322 READ_BOOL_FIELD(cterecursive);
323 READ_INT_FIELD(cterefcount);
324 READ_NODE_FIELD(ctecolnames);
325 READ_NODE_FIELD(ctecoltypes);
326 READ_NODE_FIELD(ctecoltypmods);
327 READ_NODE_FIELD(ctecolcollations);
333 * _readSetOperationStmt
335 static SetOperationStmt *
336 _readSetOperationStmt(void)
338 READ_LOCALS(SetOperationStmt);
340 READ_ENUM_FIELD(op, SetOperation);
341 READ_BOOL_FIELD(all);
342 READ_NODE_FIELD(larg);
343 READ_NODE_FIELD(rarg);
344 READ_NODE_FIELD(colTypes);
345 READ_NODE_FIELD(colTypmods);
346 READ_NODE_FIELD(colCollations);
347 READ_NODE_FIELD(groupClauses);
354 * Stuff from primnodes.h.
362 READ_STRING_FIELD(aliasname);
363 READ_NODE_FIELD(colnames);
371 READ_LOCALS(RangeVar);
373 local_node->catalogname = NULL; /* not currently saved in output
376 READ_STRING_FIELD(schemaname);
377 READ_STRING_FIELD(relname);
378 READ_ENUM_FIELD(inhOpt, InhOption);
379 READ_CHAR_FIELD(relpersistence);
380 READ_NODE_FIELD(alias);
381 READ_LOCATION_FIELD(location);
387 _readIntoClause(void)
389 READ_LOCALS(IntoClause);
391 READ_NODE_FIELD(rel);
392 READ_NODE_FIELD(colNames);
393 READ_NODE_FIELD(options);
394 READ_ENUM_FIELD(onCommit, OnCommitAction);
395 READ_STRING_FIELD(tableSpaceName);
408 READ_UINT_FIELD(varno);
409 READ_INT_FIELD(varattno);
410 READ_OID_FIELD(vartype);
411 READ_INT_FIELD(vartypmod);
412 READ_OID_FIELD(varcollid);
413 READ_UINT_FIELD(varlevelsup);
414 READ_UINT_FIELD(varnoold);
415 READ_INT_FIELD(varoattno);
416 READ_LOCATION_FIELD(location);
429 READ_OID_FIELD(consttype);
430 READ_INT_FIELD(consttypmod);
431 READ_OID_FIELD(constcollid);
432 READ_INT_FIELD(constlen);
433 READ_BOOL_FIELD(constbyval);
434 READ_BOOL_FIELD(constisnull);
435 READ_LOCATION_FIELD(location);
437 token = pg_strtok(&length); /* skip :constvalue */
438 if (local_node->constisnull)
439 token = pg_strtok(&length); /* skip "<>" */
441 local_node->constvalue = readDatum(local_node->constbyval);
454 READ_ENUM_FIELD(paramkind, ParamKind);
455 READ_INT_FIELD(paramid);
456 READ_OID_FIELD(paramtype);
457 READ_INT_FIELD(paramtypmod);
458 READ_OID_FIELD(paramcollid);
459 READ_LOCATION_FIELD(location);
472 READ_OID_FIELD(aggfnoid);
473 READ_OID_FIELD(aggtype);
474 READ_OID_FIELD(aggcollid);
475 READ_OID_FIELD(inputcollid);
476 READ_NODE_FIELD(args);
477 READ_NODE_FIELD(aggorder);
478 READ_NODE_FIELD(aggdistinct);
479 READ_BOOL_FIELD(aggstar);
480 READ_UINT_FIELD(agglevelsup);
481 READ_LOCATION_FIELD(location);
490 _readWindowFunc(void)
492 READ_LOCALS(WindowFunc);
494 READ_OID_FIELD(winfnoid);
495 READ_OID_FIELD(wintype);
496 READ_OID_FIELD(wincollid);
497 READ_OID_FIELD(inputcollid);
498 READ_NODE_FIELD(args);
499 READ_UINT_FIELD(winref);
500 READ_BOOL_FIELD(winstar);
501 READ_BOOL_FIELD(winagg);
502 READ_LOCATION_FIELD(location);
513 READ_LOCALS(ArrayRef);
515 READ_OID_FIELD(refarraytype);
516 READ_OID_FIELD(refelemtype);
517 READ_INT_FIELD(reftypmod);
518 READ_OID_FIELD(refcollid);
519 READ_NODE_FIELD(refupperindexpr);
520 READ_NODE_FIELD(reflowerindexpr);
521 READ_NODE_FIELD(refexpr);
522 READ_NODE_FIELD(refassgnexpr);
533 READ_LOCALS(FuncExpr);
535 READ_OID_FIELD(funcid);
536 READ_OID_FIELD(funcresulttype);
537 READ_BOOL_FIELD(funcretset);
538 READ_ENUM_FIELD(funcformat, CoercionForm);
539 READ_OID_FIELD(funccollid);
540 READ_OID_FIELD(inputcollid);
541 READ_NODE_FIELD(args);
542 READ_LOCATION_FIELD(location);
550 static NamedArgExpr *
551 _readNamedArgExpr(void)
553 READ_LOCALS(NamedArgExpr);
555 READ_NODE_FIELD(arg);
556 READ_STRING_FIELD(name);
557 READ_INT_FIELD(argnumber);
558 READ_LOCATION_FIELD(location);
571 READ_OID_FIELD(opno);
572 READ_OID_FIELD(opfuncid);
575 * The opfuncid is stored in the textual format primarily for debugging
576 * and documentation reasons. We want to always read it as zero to force
577 * it to be re-looked-up in the pg_operator entry. This ensures that
578 * stored rules don't have hidden dependencies on operators' functions.
579 * (We don't currently support an ALTER OPERATOR command, but might
582 local_node->opfuncid = InvalidOid;
584 READ_OID_FIELD(opresulttype);
585 READ_BOOL_FIELD(opretset);
586 READ_OID_FIELD(opcollid);
587 READ_OID_FIELD(inputcollid);
588 READ_NODE_FIELD(args);
589 READ_LOCATION_FIELD(location);
597 static DistinctExpr *
598 _readDistinctExpr(void)
600 READ_LOCALS(DistinctExpr);
602 READ_OID_FIELD(opno);
603 READ_OID_FIELD(opfuncid);
606 * The opfuncid is stored in the textual format primarily for debugging
607 * and documentation reasons. We want to always read it as zero to force
608 * it to be re-looked-up in the pg_operator entry. This ensures that
609 * stored rules don't have hidden dependencies on operators' functions.
610 * (We don't currently support an ALTER OPERATOR command, but might
613 local_node->opfuncid = InvalidOid;
615 READ_OID_FIELD(opresulttype);
616 READ_BOOL_FIELD(opretset);
617 READ_OID_FIELD(opcollid);
618 READ_OID_FIELD(inputcollid);
619 READ_NODE_FIELD(args);
620 READ_LOCATION_FIELD(location);
629 _readNullIfExpr(void)
631 READ_LOCALS(NullIfExpr);
633 READ_OID_FIELD(opno);
634 READ_OID_FIELD(opfuncid);
637 * The opfuncid is stored in the textual format primarily for debugging
638 * and documentation reasons. We want to always read it as zero to force
639 * it to be re-looked-up in the pg_operator entry. This ensures that
640 * stored rules don't have hidden dependencies on operators' functions.
641 * (We don't currently support an ALTER OPERATOR command, but might
644 local_node->opfuncid = InvalidOid;
646 READ_OID_FIELD(opresulttype);
647 READ_BOOL_FIELD(opretset);
648 READ_OID_FIELD(opcollid);
649 READ_OID_FIELD(inputcollid);
650 READ_NODE_FIELD(args);
651 READ_LOCATION_FIELD(location);
657 * _readScalarArrayOpExpr
659 static ScalarArrayOpExpr *
660 _readScalarArrayOpExpr(void)
662 READ_LOCALS(ScalarArrayOpExpr);
664 READ_OID_FIELD(opno);
665 READ_OID_FIELD(opfuncid);
668 * The opfuncid is stored in the textual format primarily for debugging
669 * and documentation reasons. We want to always read it as zero to force
670 * it to be re-looked-up in the pg_operator entry. This ensures that
671 * stored rules don't have hidden dependencies on operators' functions.
672 * (We don't currently support an ALTER OPERATOR command, but might
675 local_node->opfuncid = InvalidOid;
677 READ_BOOL_FIELD(useOr);
678 READ_OID_FIELD(inputcollid);
679 READ_NODE_FIELD(args);
680 READ_LOCATION_FIELD(location);
691 READ_LOCALS(BoolExpr);
693 /* do-it-yourself enum representation */
694 token = pg_strtok(&length); /* skip :boolop */
695 token = pg_strtok(&length); /* get field value */
696 if (strncmp(token, "and", 3) == 0)
697 local_node->boolop = AND_EXPR;
698 else if (strncmp(token, "or", 2) == 0)
699 local_node->boolop = OR_EXPR;
700 else if (strncmp(token, "not", 3) == 0)
701 local_node->boolop = NOT_EXPR;
703 elog(ERROR, "unrecognized boolop \"%.*s\"", length, token);
705 READ_NODE_FIELD(args);
706 READ_LOCATION_FIELD(location);
717 READ_LOCALS(SubLink);
719 READ_ENUM_FIELD(subLinkType, SubLinkType);
720 READ_NODE_FIELD(testexpr);
721 READ_NODE_FIELD(operName);
722 READ_NODE_FIELD(subselect);
723 READ_LOCATION_FIELD(location);
729 * _readSubPlan is not needed since it doesn't appear in stored rules.
736 _readFieldSelect(void)
738 READ_LOCALS(FieldSelect);
740 READ_NODE_FIELD(arg);
741 READ_INT_FIELD(fieldnum);
742 READ_OID_FIELD(resulttype);
743 READ_INT_FIELD(resulttypmod);
744 READ_OID_FIELD(resultcollid);
753 _readFieldStore(void)
755 READ_LOCALS(FieldStore);
757 READ_NODE_FIELD(arg);
758 READ_NODE_FIELD(newvals);
759 READ_NODE_FIELD(fieldnums);
760 READ_OID_FIELD(resulttype);
769 _readRelabelType(void)
771 READ_LOCALS(RelabelType);
773 READ_NODE_FIELD(arg);
774 READ_OID_FIELD(resulttype);
775 READ_INT_FIELD(resulttypmod);
776 READ_OID_FIELD(resultcollid);
777 READ_ENUM_FIELD(relabelformat, CoercionForm);
778 READ_LOCATION_FIELD(location);
787 _readCoerceViaIO(void)
789 READ_LOCALS(CoerceViaIO);
791 READ_NODE_FIELD(arg);
792 READ_OID_FIELD(resulttype);
793 READ_OID_FIELD(resultcollid);
794 READ_ENUM_FIELD(coerceformat, CoercionForm);
795 READ_LOCATION_FIELD(location);
801 * _readArrayCoerceExpr
803 static ArrayCoerceExpr *
804 _readArrayCoerceExpr(void)
806 READ_LOCALS(ArrayCoerceExpr);
808 READ_NODE_FIELD(arg);
809 READ_OID_FIELD(elemfuncid);
810 READ_OID_FIELD(resulttype);
811 READ_INT_FIELD(resulttypmod);
812 READ_OID_FIELD(resultcollid);
813 READ_BOOL_FIELD(isExplicit);
814 READ_ENUM_FIELD(coerceformat, CoercionForm);
815 READ_LOCATION_FIELD(location);
821 * _readConvertRowtypeExpr
823 static ConvertRowtypeExpr *
824 _readConvertRowtypeExpr(void)
826 READ_LOCALS(ConvertRowtypeExpr);
828 READ_NODE_FIELD(arg);
829 READ_OID_FIELD(resulttype);
830 READ_ENUM_FIELD(convertformat, CoercionForm);
831 READ_LOCATION_FIELD(location);
840 _readCollateExpr(void)
842 READ_LOCALS(CollateExpr);
844 READ_NODE_FIELD(arg);
845 READ_OID_FIELD(collOid);
846 READ_LOCATION_FIELD(location);
857 READ_LOCALS(CaseExpr);
859 READ_OID_FIELD(casetype);
860 READ_OID_FIELD(casecollid);
861 READ_NODE_FIELD(arg);
862 READ_NODE_FIELD(args);
863 READ_NODE_FIELD(defresult);
864 READ_LOCATION_FIELD(location);
875 READ_LOCALS(CaseWhen);
877 READ_NODE_FIELD(expr);
878 READ_NODE_FIELD(result);
879 READ_LOCATION_FIELD(location);
887 static CaseTestExpr *
888 _readCaseTestExpr(void)
890 READ_LOCALS(CaseTestExpr);
892 READ_OID_FIELD(typeId);
893 READ_INT_FIELD(typeMod);
894 READ_OID_FIELD(collation);
905 READ_LOCALS(ArrayExpr);
907 READ_OID_FIELD(array_typeid);
908 READ_OID_FIELD(array_collid);
909 READ_OID_FIELD(element_typeid);
910 READ_NODE_FIELD(elements);
911 READ_BOOL_FIELD(multidims);
912 READ_LOCATION_FIELD(location);
923 READ_LOCALS(RowExpr);
925 READ_NODE_FIELD(args);
926 READ_OID_FIELD(row_typeid);
927 READ_ENUM_FIELD(row_format, CoercionForm);
928 READ_NODE_FIELD(colnames);
929 READ_LOCATION_FIELD(location);
935 * _readRowCompareExpr
937 static RowCompareExpr *
938 _readRowCompareExpr(void)
940 READ_LOCALS(RowCompareExpr);
942 READ_ENUM_FIELD(rctype, RowCompareType);
943 READ_NODE_FIELD(opnos);
944 READ_NODE_FIELD(opfamilies);
945 READ_NODE_FIELD(inputcollids);
946 READ_NODE_FIELD(largs);
947 READ_NODE_FIELD(rargs);
955 static CoalesceExpr *
956 _readCoalesceExpr(void)
958 READ_LOCALS(CoalesceExpr);
960 READ_OID_FIELD(coalescetype);
961 READ_OID_FIELD(coalescecollid);
962 READ_NODE_FIELD(args);
963 READ_LOCATION_FIELD(location);
972 _readMinMaxExpr(void)
974 READ_LOCALS(MinMaxExpr);
976 READ_OID_FIELD(minmaxtype);
977 READ_OID_FIELD(minmaxcollid);
978 READ_OID_FIELD(inputcollid);
979 READ_ENUM_FIELD(op, MinMaxOp);
980 READ_NODE_FIELD(args);
981 READ_LOCATION_FIELD(location);
992 READ_LOCALS(XmlExpr);
994 READ_ENUM_FIELD(op, XmlExprOp);
995 READ_STRING_FIELD(name);
996 READ_NODE_FIELD(named_args);
997 READ_NODE_FIELD(arg_names);
998 READ_NODE_FIELD(args);
999 READ_ENUM_FIELD(xmloption, XmlOptionType);
1000 READ_OID_FIELD(type);
1001 READ_INT_FIELD(typmod);
1002 READ_LOCATION_FIELD(location);
1013 READ_LOCALS(NullTest);
1015 READ_NODE_FIELD(arg);
1016 READ_ENUM_FIELD(nulltesttype, NullTestType);
1017 READ_BOOL_FIELD(argisrow);
1025 static BooleanTest *
1026 _readBooleanTest(void)
1028 READ_LOCALS(BooleanTest);
1030 READ_NODE_FIELD(arg);
1031 READ_ENUM_FIELD(booltesttype, BoolTestType);
1037 * _readCoerceToDomain
1039 static CoerceToDomain *
1040 _readCoerceToDomain(void)
1042 READ_LOCALS(CoerceToDomain);
1044 READ_NODE_FIELD(arg);
1045 READ_OID_FIELD(resulttype);
1046 READ_INT_FIELD(resulttypmod);
1047 READ_OID_FIELD(resultcollid);
1048 READ_ENUM_FIELD(coercionformat, CoercionForm);
1049 READ_LOCATION_FIELD(location);
1055 * _readCoerceToDomainValue
1057 static CoerceToDomainValue *
1058 _readCoerceToDomainValue(void)
1060 READ_LOCALS(CoerceToDomainValue);
1062 READ_OID_FIELD(typeId);
1063 READ_INT_FIELD(typeMod);
1064 READ_OID_FIELD(collation);
1065 READ_LOCATION_FIELD(location);
1073 static SetToDefault *
1074 _readSetToDefault(void)
1076 READ_LOCALS(SetToDefault);
1078 READ_OID_FIELD(typeId);
1079 READ_INT_FIELD(typeMod);
1080 READ_OID_FIELD(collation);
1081 READ_LOCATION_FIELD(location);
1087 * _readCurrentOfExpr
1089 static CurrentOfExpr *
1090 _readCurrentOfExpr(void)
1092 READ_LOCALS(CurrentOfExpr);
1094 READ_UINT_FIELD(cvarno);
1095 READ_STRING_FIELD(cursor_name);
1096 READ_INT_FIELD(cursor_param);
1104 static TargetEntry *
1105 _readTargetEntry(void)
1107 READ_LOCALS(TargetEntry);
1109 READ_NODE_FIELD(expr);
1110 READ_INT_FIELD(resno);
1111 READ_STRING_FIELD(resname);
1112 READ_UINT_FIELD(ressortgroupref);
1113 READ_OID_FIELD(resorigtbl);
1114 READ_INT_FIELD(resorigcol);
1115 READ_BOOL_FIELD(resjunk);
1123 static RangeTblRef *
1124 _readRangeTblRef(void)
1126 READ_LOCALS(RangeTblRef);
1128 READ_INT_FIELD(rtindex);
1139 READ_LOCALS(JoinExpr);
1141 READ_ENUM_FIELD(jointype, JoinType);
1142 READ_BOOL_FIELD(isNatural);
1143 READ_NODE_FIELD(larg);
1144 READ_NODE_FIELD(rarg);
1145 READ_NODE_FIELD(usingClause);
1146 READ_NODE_FIELD(quals);
1147 READ_NODE_FIELD(alias);
1148 READ_INT_FIELD(rtindex);
1159 READ_LOCALS(FromExpr);
1161 READ_NODE_FIELD(fromlist);
1162 READ_NODE_FIELD(quals);
1169 * Stuff from parsenodes.h.
1173 * _readRangeTblEntry
1175 static RangeTblEntry *
1176 _readRangeTblEntry(void)
1178 READ_LOCALS(RangeTblEntry);
1180 /* put alias + eref first to make dump more legible */
1181 READ_NODE_FIELD(alias);
1182 READ_NODE_FIELD(eref);
1183 READ_ENUM_FIELD(rtekind, RTEKind);
1185 switch (local_node->rtekind)
1188 READ_OID_FIELD(relid);
1189 READ_CHAR_FIELD(relkind);
1192 READ_NODE_FIELD(subquery);
1195 READ_ENUM_FIELD(jointype, JoinType);
1196 READ_NODE_FIELD(joinaliasvars);
1199 READ_NODE_FIELD(funcexpr);
1200 READ_NODE_FIELD(funccoltypes);
1201 READ_NODE_FIELD(funccoltypmods);
1202 READ_NODE_FIELD(funccolcollations);
1205 READ_NODE_FIELD(values_lists);
1208 READ_STRING_FIELD(ctename);
1209 READ_UINT_FIELD(ctelevelsup);
1210 READ_BOOL_FIELD(self_reference);
1211 READ_NODE_FIELD(ctecoltypes);
1212 READ_NODE_FIELD(ctecoltypmods);
1213 READ_NODE_FIELD(ctecolcollations);
1216 elog(ERROR, "unrecognized RTE kind: %d",
1217 (int) local_node->rtekind);
1221 READ_BOOL_FIELD(inh);
1222 READ_BOOL_FIELD(inFromCl);
1223 READ_UINT_FIELD(requiredPerms);
1224 READ_OID_FIELD(checkAsUser);
1225 READ_BITMAPSET_FIELD(selectedCols);
1226 READ_BITMAPSET_FIELD(modifiedCols);
1235 * Given a character string representing a node tree, parseNodeString creates
1236 * the internal node structure.
1238 * The string to be read must already have been loaded into pg_strtok().
1241 parseNodeString(void)
1247 token = pg_strtok(&length);
1249 #define MATCH(tokname, namelen) \
1250 (length == namelen && memcmp(token, tokname, namelen) == 0)
1252 if (MATCH("QUERY", 5))
1253 return_value = _readQuery();
1254 else if (MATCH("SORTGROUPCLAUSE", 15))
1255 return_value = _readSortGroupClause();
1256 else if (MATCH("WINDOWCLAUSE", 12))
1257 return_value = _readWindowClause();
1258 else if (MATCH("ROWMARKCLAUSE", 13))
1259 return_value = _readRowMarkClause();
1260 else if (MATCH("COMMONTABLEEXPR", 15))
1261 return_value = _readCommonTableExpr();
1262 else if (MATCH("SETOPERATIONSTMT", 16))
1263 return_value = _readSetOperationStmt();
1264 else if (MATCH("ALIAS", 5))
1265 return_value = _readAlias();
1266 else if (MATCH("RANGEVAR", 8))
1267 return_value = _readRangeVar();
1268 else if (MATCH("INTOCLAUSE", 10))
1269 return_value = _readIntoClause();
1270 else if (MATCH("VAR", 3))
1271 return_value = _readVar();
1272 else if (MATCH("CONST", 5))
1273 return_value = _readConst();
1274 else if (MATCH("PARAM", 5))
1275 return_value = _readParam();
1276 else if (MATCH("AGGREF", 6))
1277 return_value = _readAggref();
1278 else if (MATCH("WINDOWFUNC", 10))
1279 return_value = _readWindowFunc();
1280 else if (MATCH("ARRAYREF", 8))
1281 return_value = _readArrayRef();
1282 else if (MATCH("FUNCEXPR", 8))
1283 return_value = _readFuncExpr();
1284 else if (MATCH("NAMEDARGEXPR", 12))
1285 return_value = _readNamedArgExpr();
1286 else if (MATCH("OPEXPR", 6))
1287 return_value = _readOpExpr();
1288 else if (MATCH("DISTINCTEXPR", 12))
1289 return_value = _readDistinctExpr();
1290 else if (MATCH("NULLIFEXPR", 10))
1291 return_value = _readNullIfExpr();
1292 else if (MATCH("SCALARARRAYOPEXPR", 17))
1293 return_value = _readScalarArrayOpExpr();
1294 else if (MATCH("BOOLEXPR", 8))
1295 return_value = _readBoolExpr();
1296 else if (MATCH("SUBLINK", 7))
1297 return_value = _readSubLink();
1298 else if (MATCH("FIELDSELECT", 11))
1299 return_value = _readFieldSelect();
1300 else if (MATCH("FIELDSTORE", 10))
1301 return_value = _readFieldStore();
1302 else if (MATCH("RELABELTYPE", 11))
1303 return_value = _readRelabelType();
1304 else if (MATCH("COERCEVIAIO", 11))
1305 return_value = _readCoerceViaIO();
1306 else if (MATCH("ARRAYCOERCEEXPR", 15))
1307 return_value = _readArrayCoerceExpr();
1308 else if (MATCH("CONVERTROWTYPEEXPR", 18))
1309 return_value = _readConvertRowtypeExpr();
1310 else if (MATCH("COLLATE", 7))
1311 return_value = _readCollateExpr();
1312 else if (MATCH("CASE", 4))
1313 return_value = _readCaseExpr();
1314 else if (MATCH("WHEN", 4))
1315 return_value = _readCaseWhen();
1316 else if (MATCH("CASETESTEXPR", 12))
1317 return_value = _readCaseTestExpr();
1318 else if (MATCH("ARRAY", 5))
1319 return_value = _readArrayExpr();
1320 else if (MATCH("ROW", 3))
1321 return_value = _readRowExpr();
1322 else if (MATCH("ROWCOMPARE", 10))
1323 return_value = _readRowCompareExpr();
1324 else if (MATCH("COALESCE", 8))
1325 return_value = _readCoalesceExpr();
1326 else if (MATCH("MINMAX", 6))
1327 return_value = _readMinMaxExpr();
1328 else if (MATCH("XMLEXPR", 7))
1329 return_value = _readXmlExpr();
1330 else if (MATCH("NULLTEST", 8))
1331 return_value = _readNullTest();
1332 else if (MATCH("BOOLEANTEST", 11))
1333 return_value = _readBooleanTest();
1334 else if (MATCH("COERCETODOMAIN", 14))
1335 return_value = _readCoerceToDomain();
1336 else if (MATCH("COERCETODOMAINVALUE", 19))
1337 return_value = _readCoerceToDomainValue();
1338 else if (MATCH("SETTODEFAULT", 12))
1339 return_value = _readSetToDefault();
1340 else if (MATCH("CURRENTOFEXPR", 13))
1341 return_value = _readCurrentOfExpr();
1342 else if (MATCH("TARGETENTRY", 11))
1343 return_value = _readTargetEntry();
1344 else if (MATCH("RANGETBLREF", 11))
1345 return_value = _readRangeTblRef();
1346 else if (MATCH("JOINEXPR", 8))
1347 return_value = _readJoinExpr();
1348 else if (MATCH("FROMEXPR", 8))
1349 return_value = _readFromExpr();
1350 else if (MATCH("RTE", 3))
1351 return_value = _readRangeTblEntry();
1352 else if (MATCH("NOTIFY", 6))
1353 return_value = _readNotifyStmt();
1354 else if (MATCH("DECLARECURSOR", 13))
1355 return_value = _readDeclareCursorStmt();
1358 elog(ERROR, "badly formatted node string \"%.32s\"...", token);
1359 return_value = NULL; /* keep compiler quiet */
1362 return (Node *) return_value;
1369 * Given a string representation of a constant, recreate the appropriate
1370 * Datum. The string representation embeds length info, but not byValue,
1371 * so we must be told that.
1374 readDatum(bool typbyval)
1384 * read the actual length of the value
1386 token = pg_strtok(&tokenLength);
1387 length = atoui(token);
1389 token = pg_strtok(&tokenLength); /* read the '[' */
1390 if (token == NULL || token[0] != '[')
1391 elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu",
1392 token ? (const char *) token : "[NULL]",
1393 (unsigned long) length);
1397 if (length > (Size) sizeof(Datum))
1398 elog(ERROR, "byval datum but length = %lu",
1399 (unsigned long) length);
1401 s = (char *) (&res);
1402 for (i = 0; i < (Size) sizeof(Datum); i++)
1404 token = pg_strtok(&tokenLength);
1405 s[i] = (char) atoi(token);
1408 else if (length <= 0)
1412 s = (char *) palloc(length);
1413 for (i = 0; i < length; i++)
1415 token = pg_strtok(&tokenLength);
1416 s[i] = (char) atoi(token);
1418 res = PointerGetDatum(s);
1421 token = pg_strtok(&tokenLength); /* read the ']' */
1422 if (token == NULL || token[0] != ']')
1423 elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu",
1424 token ? (const char *) token : "[NULL]",
1425 (unsigned long) length);