@@ -10,14 +10,17 @@ array_of[EXP] -> $EXP (%comma $EXP {% last %}):* {% ([head, tail]) => {
1010# https://www.postgresql.org/docs/12/sql-select.html
1111
1212select_statement
13- -> select_what select_from :? select_where :? ( select_groupby select_having :?):? select_order_by :? select_limit_offset :? select_for :?
13+ -> select_what select_from :? select_where :? ( select_groupby select_having :?):? select_order_by :? select_limit_offset :? ( select_for select_skip :?) :?
1414 {% x => {
15- let [what, from, where, _groupBy, orderBy, limit, selectFor ] = x;
15+ let [what, from, where, _groupBy, orderBy, limit, _selectFor ] = x;
1616 from = unwrap (from);
1717 let groupBy = _groupBy && _groupBy[0 ];
1818 let having = _groupBy && _groupBy[1 ];
1919 groupBy = groupBy && (groupBy .length === 1 && groupBy[0 ].type === ' list' ? groupBy[0 ].expressions : groupBy);
2020 having = having && unwrap (having);
21+ let selectFor = _selectFor && _selectFor[0 ];
22+ let skip = _selectFor && _selectFor[1 ];
23+ skip = unwrap (skip);
2124 return track (x, {
2225 ... what,
2326 ... from ? { from: Array .isArray (from) ? from : [from] } : {},
@@ -27,6 +30,7 @@ select_statement
2730 ... orderBy ? { orderBy } : {},
2831 ... where ? { where } : {},
2932 ... selectFor ? { for: selectFor[1 ] } : {},
33+ ... skip ? { skip } : {},
3034 type: ' select' ,
3135 });
3236 } %}
@@ -201,6 +205,9 @@ select_for -> %kw_for (
201205 | kw_share {% x => track (x, {type: ' share' }) %}
202206 | kw_key kw_share {% x => track (x, {type: ' key share' }) %} )
203207
208+ # [ NOWAIT | SKIP LOCKED ]
209+ select_skip -> ( kw_nowait {% x => track (x, {type: ' nowait' }) %} | kw_skip kw_locked {% x => track (x, {type: ' skip locked' }) %} )
210+
204211select_order_by -> ( %kw_order kw_by ) select_order_by_expr ( comma select_order_by_expr {% last%} ):* {% ([_ , head , tail ]) => {
205212 return [head, ... (tail || [])];
206213} %}
0 commit comments