File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -106,4 +106,6 @@ reports the result columns and parameters:
106106]
107107```
108108
109- Pass ` --ast ` to also include each statement's parsed AST under an ` ast ` key.
109+ Pass ` --ast ` to also include each statement's parsed AST under an ` ast ` key. It
110+ has the same shape as the output of [ ` parse ` ] ( parse.md ) , with every node tagged
111+ by type.
Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ The output is a JSON array with one object per statement:
4848 "name" : " GetAuthor" ,
4949 "cmd" : " :one" ,
5050 "ast" : {
51+ "tag" : " RawStmt" ,
5152 "Stmt" : {
5253 "..." : " ..."
5354 },
@@ -60,3 +61,29 @@ The output is a JSON array with one object per statement:
6061
6162Statements without a ` -- name: ` annotation (for example schema DDL) omit the
6263` name ` and ` cmd ` fields.
64+
65+ ## Node types
66+
67+ Every node in the AST carries a ` tag ` naming its type. Some nodes have no
68+ fields of their own, so without it a star, a null literal and an untranslated
69+ clause would all print as ` {} ` .
70+
71+ ``` json
72+ "Val" : {
73+ "tag" : " ColumnRef" ,
74+ "Name" : " " ,
75+ "Fields" : {
76+ "tag" : " List" ,
77+ "Items" : [
78+ {
79+ "tag" : " A_Star"
80+ }
81+ ]
82+ },
83+ "Location" : 93
84+ }
85+ ```
86+
87+ A ` tag ` of ` TODO ` marks a clause the dialect's converter does not translate
88+ yet. It means the clause was parsed but is not represented in the AST, not that
89+ the clause was absent from the query.
Original file line number Diff line number Diff line change 2424 }
2525 ],
2626 "ast": {
27+ "tag": "RawStmt",
2728 "Stmt": {
29+ "tag": "SelectStmt",
2830 "DistinctClause": {
31+ "tag": "List",
2932 "Items": null
3033 },
3134 "IntoClause": null,
3235 "TargetList": {
36+ "tag": "List",
3337 "Items": [
3438 {
39+ "tag": "ResTarget",
3540 "Name": null,
3641 "Indirection": {
42+ "tag": "List",
3743 "Items": null
3844 },
3945 "Val": {
46+ "tag": "ColumnRef",
4047 "Name": "",
4148 "Fields": {
49+ "tag": "List",
4250 "Items": [
4351 {
52+ "tag": "String",
4453 "Str": "name"
4554 }
4655 ]
5261 ]
5362 },
5463 "FromClause": {
64+ "tag": "List",
5565 "Items": [
5666 {
67+ "tag": "RangeVar",
5768 "Catalogname": null,
5869 "Schemaname": null,
5970 "Relname": "authors",
6576 ]
6677 },
6778 "WhereClause": {
79+ "tag": "A_Expr",
6880 "Kind": 1,
6981 "Name": {
82+ "tag": "List",
7083 "Items": [
7184 {
85+ "tag": "String",
7286 "Str": "="
7387 }
7488 ]
7589 },
7690 "Lexpr": {
91+ "tag": "ColumnRef",
7792 "Name": "",
7893 "Fields": {
94+ "tag": "List",
7995 "Items": [
8096 {
97+ "tag": "String",
8198 "Str": "id"
8299 }
83100 ]
84101 },
85102 "Location": 59
86103 },
87104 "Rexpr": {
105+ "tag": "ParamRef",
88106 "Number": 1,
89107 "Location": 64,
90108 "Dollar": true
91109 },
92110 "Location": 62
93111 },
94112 "GroupClause": {
113+ "tag": "List",
95114 "Items": null
96115 },
97- "HavingClause": {},
116+ "HavingClause": {
117+ "tag": "TODO"
118+ },
98119 "WindowClause": {
120+ "tag": "List",
99121 "Items": null
100122 },
101123 "ValuesLists": {
124+ "tag": "List",
102125 "Items": null
103126 },
104127 "SortClause": {
128+ "tag": "List",
105129 "Items": null
106130 },
107- "LimitOffset": {},
108- "LimitCount": {},
131+ "LimitOffset": {
132+ "tag": "TODO"
133+ },
134+ "LimitCount": {
135+ "tag": "TODO"
136+ },
109137 "LockingClause": {
138+ "tag": "List",
110139 "Items": null
111140 },
112141 "WithClause": null,
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": null,
810 "IntoClause": null,
911 "TargetList": {
12+ "tag": "List",
1013 "Items": [
1114 {
15+ "tag": "ResTarget",
1216 "Name": null,
1317 "Indirection": null,
1418 "Val": {
19+ "tag": "A_Const",
1520 "Val": {
21+ "tag": "Integer",
1622 "Ival": 1
1723 },
1824 "Location": 31
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": null,
810 "IntoClause": null,
911 "TargetList": {
12+ "tag": "List",
1013 "Items": [
1114 {
15+ "tag": "ResTarget",
1216 "Name": null,
1317 "Indirection": null,
1418 "Val": {
19+ "tag": "A_Const",
1520 "Val": {
21+ "tag": "Integer",
1622 "Ival": 1
1723 },
1824 "Location": 30
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": null,
810 "IntoClause": null,
911 "TargetList": {
12+ "tag": "List",
1013 "Items": [
1114 {
15+ "tag": "ResTarget",
1216 "Name": null,
1317 "Indirection": null,
1418 "Val": {
19+ "tag": "A_Const",
1520 "Val": {
21+ "tag": "Integer",
1622 "Ival": 1
1723 },
1824 "Location": 30
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": null,
810 "IntoClause": null,
911 "TargetList": {
12+ "tag": "List",
1013 "Items": [
1114 {
15+ "tag": "ResTarget",
1216 "Name": null,
1317 "Indirection": null,
1418 "Val": {
19+ "tag": "A_Const",
1520 "Val": {
21+ "tag": "Integer",
1622 "Ival": 1
1723 },
1824 "Location": 30
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": null,
810 "IntoClause": null,
911 "TargetList": {
12+ "tag": "List",
1013 "Items": [
1114 {
15+ "tag": "ResTarget",
1216 "Name": null,
1317 "Indirection": null,
1418 "Val": {
19+ "tag": "A_Const",
1520 "Val": {
21+ "tag": "Integer",
1622 "Ival": 1
1723 },
1824 "Location": 30
2228 ]
2329 },
2430 "FromClause": {
31+ "tag": "List",
2532 "Items": null
2633 },
2734 "WhereClause": null,
2835 "GroupClause": {
36+ "tag": "List",
2937 "Items": null
3038 },
3139 "HavingClause": null,
3240 "WindowClause": {
41+ "tag": "List",
3342 "Items": []
3443 },
3544 "ValuesLists": null,
Original file line number Diff line number Diff line change 33 "name": "GetValue",
44 "cmd": ":one",
55 "ast": {
6+ "tag": "RawStmt",
67 "Stmt": {
8+ "tag": "SelectStmt",
79 "DistinctClause": {
10+ "tag": "List",
811 "Items": null
912 },
1013 "IntoClause": null,
1114 "TargetList": {
15+ "tag": "List",
1216 "Items": [
1317 {
18+ "tag": "ResTarget",
1419 "Name": null,
1520 "Indirection": {
21+ "tag": "List",
1622 "Items": null
1723 },
1824 "Val": {
25+ "tag": "A_Const",
1926 "Val": {
27+ "tag": "Integer",
2028 "Ival": 1
2129 },
2230 "Location": 30
2634 ]
2735 },
2836 "FromClause": {
37+ "tag": "List",
2938 "Items": null
3039 },
31- "WhereClause": {},
40+ "WhereClause": {
41+ "tag": "TODO"
42+ },
3243 "GroupClause": {
44+ "tag": "List",
3345 "Items": null
3446 },
35- "HavingClause": {},
47+ "HavingClause": {
48+ "tag": "TODO"
49+ },
3650 "WindowClause": {
51+ "tag": "List",
3752 "Items": null
3853 },
3954 "ValuesLists": {
55+ "tag": "List",
4056 "Items": null
4157 },
4258 "SortClause": {
59+ "tag": "List",
4360 "Items": null
4461 },
45- "LimitOffset": {},
46- "LimitCount": {},
62+ "LimitOffset": {
63+ "tag": "TODO"
64+ },
65+ "LimitCount": {
66+ "tag": "TODO"
67+ },
4768 "LockingClause": {
69+ "tag": "List",
4870 "Items": null
4971 },
5072 "WithClause": null,
You can’t perform that action at this time.
0 commit comments