Skip to content

Commit 93ae22c

Browse files
committed
Add support for LIMIT ... OFFSET
1 parent 1ab2639 commit 93ae22c

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

src/mysql_parser/mysql_lexer.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ union MYSQL_YYSTYPE;
6262
"NULL" { return TOKEN_NULL_KEYWORD; }
6363
"NOT" { return TOKEN_NOT; }
6464

65+
"OFFSET" { return TOKEN_OFFSET; }
6566

6667
"DELETE" { return TOKEN_DELETE; }
6768
"LOW_PRIORITY" { return TOKEN_LOW_PRIORITY; }

src/mysql_parser/mysql_parser.y

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ int mysql_yylex(union MYSQL_YYSTYPE* yylval_param, yyscan_t yyscanner, MysqlPars
6464
/* TOKEN_FULL is already declared */
6565
%token TOKEN_BEGIN TOKEN_COMMIT /* Added for BEGIN/COMMIT */
6666
%token TOKEN_IS TOKEN_NULL_KEYWORD TOKEN_NOT /* Added for IS NULL / IS NOT NULL */
67-
67+
%token TOKEN_OFFSET /* Added for LIMIT ... OFFSET ... */
6868

6969
%token <str_val> TOKEN_QUIT
7070
%token <str_val> TOKEN_IDENTIFIER
@@ -1119,12 +1119,22 @@ opt_limit_clause:
11191119
$$->addChild($2); // count
11201120
}
11211121
| TOKEN_LIMIT number_literal_node TOKEN_COMMA number_literal_node { // LIMIT offset, count
1122-
$$ = new MysqlParser::AstNode(MysqlParser::NodeType::NODE_LIMIT_CLAUSE);
1122+
// Standard SQL: LIMIT row_count OFFSET offset_row
1123+
// MySQL legacy: LIMIT offset_row, row_count
1124+
// Current AST: first child is offset, second is count for this form.
1125+
$$ = new MysqlParser::AstNode(MysqlParser::NodeType::NODE_LIMIT_CLAUSE, "OFFSET_COUNT");
11231126
$$->addChild($2); // offset
11241127
$$->addChild($4); // count
11251128
}
11261129
// MySQL also supports LIMIT count OFFSET offset, but that's more complex to add here without ambiguity
11271130
// For now, sticking to the common forms.
1131+
| TOKEN_LIMIT number_literal_node TOKEN_OFFSET number_literal_node { // LIMIT count OFFSET offset
1132+
// Standard SQL: LIMIT row_count OFFSET offset_row
1133+
// Current AST: first child is count, second is offset for this form.
1134+
$$ = new MysqlParser::AstNode(MysqlParser::NodeType::NODE_LIMIT_CLAUSE, "COUNT_OFFSET");
1135+
$$->addChild($2); // count
1136+
$$->addChild($4); // offset
1137+
}
11281138
;
11291139

11301140
opt_group_by_clause:

0 commit comments

Comments
 (0)