-
Notifications
You must be signed in to change notification settings - Fork 0
/
bnf
231 lines (132 loc) · 6.16 KB
/
bnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# 操作符
<plus_sign> ::= +
<minus_sign> ::= -
<asterisk> ::= *
<solidus> ::= /
<sign> ::= <plus_sign> | <minus_sign>
# 符号
<comma> ::= ,
<period> ::= .
<left_paren> ::= (
<right_paren> ::= )
# 基础类型
<chars> ::= [a-zA-Z_]
<digit> ::= [0-9]
# 基础派生类
<truth_value> ::= TRUE | FALSE | UNKNOWN
<identifier> ::= <chars>
<column_name> ::= <identifier>
<set_quantifier> ::= DISTINCT | ALL
<unsigned_number> ::= <digit> [ <period> [ <digit> ] ] | <period> <digit>
<number> ::= [ sign ] [unsigned_number]
# 暂时只支持数字与字符串
<value_expression> ::= <numeric_value_expression> | <string_value_expression>
<numeric_value_expression> ::= <term> | <numeric_value_expression> <plus_sign> <term> | <numeric_value_expression> <minus_sign> <term>
<term> ::= <factor> | <term> <asterisk> <factor> | <term> <solidus> <factor>
<factor> ::= [<sign>] <numeric_primary>
<numeric_primary> ::= <unsigned_number> | <column_reference> | <scalar_subquery> | <left_paren> <value_expression> <right_parent>
# case, 暂不支持case
<case_expression> ::=
CASE <case_operand>
<simple_when_clause> ...
[ <else_clause> ]
END
<case_operand> ::= <value_expression>
<simple_when_clause> ::= WHEN <when_operand> THEN <result>
<when_operand> ::= <value_expression>
<result> ::= <result_expression> | NULL
<result_expression> ::= <value_expression>
# cast, 暂不支持cast
# <cast_expression> ::=
# CAST <left_paren> <cast_operand> AS <cast_target> <right_paren>
# <cast_operand> ::= <value_expression> | NULL
# <cast_target> ::= <qualified_name> | <data_type>
<column_reference> ::= [ <qualifier> <period> ] <column_name>
<scalar_subquery> ::= <subquery>
<string_value_expression> ::= <chars>
<query> ::= SELECT [ <set_quantifier> ] <select_list> <table_expression>
<select_list> ::= <asterisk> | <select_sublist> [ {<comma> <select_sublist>}... ]
<select_sublist> ::= <derived_column> | <qualifier> <period> <asterisk>
<derived_column> ::= <value_expression> [ <as_clause> ]
<as_clause> ::= [ AS ] <column_name>
<qualifier> ::= <table_name> | <correlation_name>
<correlation_name> ::= <identifier>
<table_name> ::= <qualified_name>
<qualified_name> ::= [ <schema_name> <period> ] <qualified_identifier>
<schema_name> ::= [ <catalog_name> <period> ] <unqualified_schema_name>
<catalog_name> ::= <identifier>
<unqualified_schema_name> ::= <identifier>
<qualified_identifier> ::= <identifier>
<qualified_local_table_name>
// table
<table_expression> ::= <from_clause> [ <where_clause> ] [ <group_by_clause> ] [ <having_clause> ]
<from_clause> ::= FROM <table_reference> [ { <comma> <table_reference> }... ]
<table_reference> ::=
<table_name> [ <correlation_specification> ]
| <derived_table> <correlation_specification>
| <joined_table>
<correlation_specification> ::= [ AS ] <correlation_name> [ <left_paren> <derived_column_list> <right_paren> ]
<derived_table> ::= <table_subquery>
<table_subquery> ::= <subquery>
<subquery> ::= <left_paren> <query_expression> <right_paren>
<query_expression> ::= <query_expression_body>
<query_expression_body> ::= <non_join_query_expression> | <joined_table>
<non_join_query_expression> ::= <non_join_query_term>
| <query_expression_body> UNION [ ALL | DISTINCT ] <query_term>
<query_term> ::= <non_join_query_term> | <joined_table>
<non_join_query_term> ::= <non_join_query_primary>
<query_primary> ::= <non_join_query_primary> | <joined_table>
<non_join_query_primary> ::= <simple_table> | <left_paren> <non_join_query_expression> <right_paren>
<simple_table> ::= <query_specification>
<query_specification> ::= SELECT [ <set_quantifier> ] <select_list> <table_expression>
<derived_column_list> ::= <column_name_list>
<column_name_list> ::= <column_name> [ {<comma> <column_name>}...]
<joined_table> ::= <qualified_join> | <left_paren> <joined_table> <right_paren>
<qualified_join> ::= <table_reference> [ <join_type> ] JOIN <table_reference> [ <join_specification> ]
<join_type> ::= INNER | <outer_join_type> [ OUTER ] | UNION
<outer_join_type> ::= LEFT | RIGHT | FULL
<join_specification> ::= <join_condition> | <named_columns_join>
<join_condition> ::= ON <search_condition>
<search_condition> ::= <boolean_term> | <search_condition> OR <boolean_term>
<boolean_term> ::= <boolean_factor> | <boolean_term> AND <boolean_factor>
<boolean_factor> ::= [ NOT ] <boolean_test>
<boolean_test> ::= <boolean_primary> [ IS [ NOT ] <truth_value> ]
<boolean_primary> ::= <predicate> | <left_paren> <search_condition> <right_paren>
<predicate> ::=
<comparison_predicate>
| <between_predicate>
| <in_predicate>
| <like_predicate>
| <null_predicate>
<comparison_predicate> ::= <row_value_constructor> <comp_op> <row_value_constructor>
<equals_operator> ::= =
<not_equals_operator> ::= <>
<less_than_operator> ::= <
<greater_than_operator> ::= >
<less_than_or_equals_operator> ::= <=
<greater_than_or_equals_operator> ::= >=
<comp_op> ::=
<equals_operator>
| <not_equals_operator>
| <less_than_operator>
| <greater_than_operator>
| <less_than_or_equals_operator>
| <greater_than_or_equals_operator>
<row_value_constructor> ::= <row_value_constructor_element>
| <left_paren> <row_value_constructor_list> <right_paren>
| <row_subquery>
<row_value_constructor_element> ::= <value_expression>
| <null_specification>
| <default_specification>
<null_specification> ::= NULL
<default_specification> = DEFAULT
<row_value_constructor_list> ::= <row_value_constructor_element> [ { <comma> <row_value_constructor_element> } ... ]
<row_subquery> ::= <subquery>
<between_predicate> ::= <row_value_constructor> [ NOT ] BETWEEN <row_value_constructor> AND <row_value_constructor>
<in_predicate> ::= <row_value_constructor> [ NOT ] IN <in_predicate_value>
<in_predicate_value> ::= <table_subquery> | <left_paren> <in_value_list> <right_paren>
<in_value_list> ::= <value_expression> { <comma> <value_expression> } ...
<like_predicate> ::= <match_value> [ NOT ] LIKE <pattern>
<match_value> ::= <identifier>
<pattern> ::= <string> // 简单点
<null_predicate> ::= <row_value_constructor> IS [ NOT ] NULL