11
11
*
12
12
*
13
13
* IDENTIFICATION
14
- * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.676 2009/08/02 22:14:52 tgl Exp $
14
+ * $PostgreSQL: pgsql/src/backend/parser/gram.y,v 2.677 2009/08/18 23:40:20 tgl Exp $
15
15
*
16
16
* HISTORY
17
17
* AUTHOR DATE MAJOR EVENT
@@ -331,7 +331,8 @@ static TypeName *TableFuncTypeName(List *columns);
331
331
%type <ival> opt_column event cursor_options opt_hold opt_set_data
332
332
%type <objtype> reindex_type drop_type comment_type
333
333
334
- %type <node> fetch_direction select_limit_value select_offset_value
334
+ %type <node> fetch_direction limit_clause select_limit_value
335
+ offset_clause select_offset_value
335
336
select_offset_value2 opt_select_fetch_first_value
336
337
%type <ival> row_or_rows first_or_next
337
338
@@ -7228,14 +7229,20 @@ sortby: a_expr USING qual_all_Op opt_nulls_order
7228
7229
7229
7230
7230
7231
select_limit:
7231
- LIMIT select_limit_value OFFSET select_offset_value
7232
- { $$ = list_make2($4 , $2 ); }
7233
- | OFFSET select_offset_value LIMIT select_limit_value
7234
- { $$ = list_make2($2 , $4 ); }
7235
- | LIMIT select_limit_value
7236
- { $$ = list_make2(NULL , $2 ); }
7237
- | OFFSET select_offset_value
7238
- { $$ = list_make2($2 , NULL ); }
7232
+ limit_clause offset_clause { $$ = list_make2($2 , $1 ); }
7233
+ | offset_clause limit_clause { $$ = list_make2($1 , $2 ); }
7234
+ | limit_clause { $$ = list_make2(NULL , $1 ); }
7235
+ | offset_clause { $$ = list_make2($1 , NULL ); }
7236
+ ;
7237
+
7238
+ opt_select_limit:
7239
+ select_limit { $$ = $1 ; }
7240
+ | /* EMPTY */ { $$ = list_make2(NULL ,NULL ); }
7241
+ ;
7242
+
7243
+ limit_clause:
7244
+ LIMIT select_limit_value
7245
+ { $$ = $2 ; }
7239
7246
| LIMIT select_limit_value ' ,' select_offset_value
7240
7247
{
7241
7248
/* Disabled because it was too confusing, bjm 2002-02-18 */
@@ -7245,19 +7252,17 @@ select_limit:
7245
7252
errhint(" Use separate LIMIT and OFFSET clauses." ),
7246
7253
parser_errposition(@1 )));
7247
7254
}
7248
- /* SQL:2008 syntax variants */
7249
- | OFFSET select_offset_value2 row_or_rows
7250
- { $$ = list_make2($2 , NULL ); }
7255
+ /* SQL:2008 syntax */
7251
7256
| FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7252
- { $$ = list_make2(NULL , $3 ); }
7253
- | OFFSET select_offset_value2 row_or_rows FETCH first_or_next opt_select_fetch_first_value row_or_rows ONLY
7254
- { $$ = list_make2($2 , $6 ); }
7257
+ { $$ = $3 ; }
7255
7258
;
7256
7259
7257
- opt_select_limit:
7258
- select_limit { $$ = $1 ; }
7259
- | /* EMPTY */
7260
- { $$ = list_make2(NULL ,NULL ); }
7260
+ offset_clause:
7261
+ OFFSET select_offset_value
7262
+ { $$ = $2 ; }
7263
+ /* SQL:2008 syntax */
7264
+ | OFFSET select_offset_value2 row_or_rows
7265
+ { $$ = $2 ; }
7261
7266
;
7262
7267
7263
7268
select_limit_value:
@@ -7269,19 +7274,20 @@ select_limit_value:
7269
7274
}
7270
7275
;
7271
7276
7277
+ select_offset_value:
7278
+ a_expr { $$ = $1 ; }
7279
+ ;
7280
+
7272
7281
/*
7273
7282
* Allowing full expressions without parentheses causes various parsing
7274
7283
* problems with the trailing ROW/ROWS key words. SQL only calls for
7275
- * constants, so we allow the rest only with parentheses.
7284
+ * constants, so we allow the rest only with parentheses. If omitted,
7285
+ * default to 1.
7276
7286
*/
7277
7287
opt_select_fetch_first_value:
7278
- SignedIconst { $$ = makeIntConst($1 , @1 ); }
7279
- | ' (' a_expr ' )' { $$ = $2 ; }
7280
- | /* EMPTY*/ { $$ = makeIntConst(1 , -1 ); }
7281
- ;
7282
-
7283
- select_offset_value:
7284
- a_expr { $$ = $1 ; }
7288
+ SignedIconst { $$ = makeIntConst($1 , @1 ); }
7289
+ | ' (' a_expr ' )' { $$ = $2 ; }
7290
+ | /* EMPTY*/ { $$ = makeIntConst(1 , -1 ); }
7285
7291
;
7286
7292
7287
7293
/*
@@ -7293,16 +7299,14 @@ select_offset_value2:
7293
7299
;
7294
7300
7295
7301
/* noise words */
7296
- row_or_rows:
7297
- ROW { $$ = 0 ; }
7298
- | ROWS { $$ = 0 ; }
7299
- ;
7302
+ row_or_rows: ROW { $$ = 0 ; }
7303
+ | ROWS { $$ = 0 ; }
7304
+ ;
7305
+
7306
+ first_or_next: FIRST_P { $$ = 0 ; }
7307
+ | NEXT { $$ = 0 ; }
7308
+ ;
7300
7309
7301
- /* noise words */
7302
- first_or_next:
7303
- FIRST_P { $$ = 0 ; }
7304
- | NEXT { $$ = 0 ; }
7305
- ;
7306
7310
7307
7311
group_clause:
7308
7312
GROUP_P BY expr_list { $$ = $3 ; }
0 commit comments