@@ -115,16 +115,17 @@ table_ref_commalist ->
115
115
| table_ref_commalist _ "," _ table_ref {% d => ({ table_refs: (d[0 ].table_refs || []).concat (d[4 ]) }) %}
116
116
117
117
@{%
118
- function tableRef (d , onOffset ) {
118
+ function tableRef (d , onOffset , alias , using ) {
119
119
if (! onOffset) onOffset = 0 ;
120
120
const ref = {
121
121
type: ' table_ref' ,
122
122
side: ((d[1 ]|| [])[1 ]),
123
123
left: d[0 ],
124
124
right: d[4 ],
125
- on: d[onOffset+ 8 ]
125
+ on: d[onOffset+ 8 ],
126
+ using
126
127
};
127
- if (onOffset ) ref .alias = d[6 ];
128
+ if (alias ) ref .alias = d[6 ];
128
129
return ref;
129
130
}
130
131
%}
@@ -134,8 +135,16 @@ table_ref ->
134
135
| table {% d => d[0 ] %}
135
136
| table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ table __ ON __ expr {% x => tableRef (x,0 ) %}
136
137
| table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ table __ ON ( "(" _ expr _ ")" ) {% x => tableRef (x,0 ) %}
137
- | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ query_spec ( AS __ | __ ) identifier __ ON __ expr {% x => tableRef (x,2 ) %}
138
- | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ query_spec ( AS __ | __ ) identifier __ ON ( "(" _ expr _ ")" ) {% x => tableRef (x,2 ) %}
138
+ | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ query_spec ( AS __ | __ ) identifier __ ON __ expr {% x => tableRef (x,2 ,true ) %}
139
+ | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ query_spec ( AS __ | __ ) identifier __ ON ( "(" _ expr _ ")" ) {% x => tableRef (x,2 ,true ) %}
140
+
141
+ | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ table __ USING _ "(" _ identifier_comma_list _ ")" {% x => tableRef (x,2 , false ,true ) %}
142
+ | table_ref ( __ LEFT __ | __ RIGHT __ | __ INNER __ | __ ) JOIN __ query_spec ( AS __ | __ ) identifier __ USING _ "(" _ identifier_comma_list _ ")" {% x => tableRef (x,4 , true ,true ) %}
143
+
144
+
145
+ identifier_comma_list ->
146
+ identifier {% d => [d[0 ]] %}
147
+ | identifier_comma_list _ "," _ identifier {% d => d[0 ].concat (d[2 ]) %}
139
148
140
149
table ->
141
150
identifier {% d => ({type: ' table' , table: d[0 ].value }) %}
0 commit comments