diff --git a/vlib/v/gen/sql.v b/vlib/v/gen/sql.v index 9bdce67866..d94dc19d03 100644 --- a/vlib/v/gen/sql.v +++ b/vlib/v/gen/sql.v @@ -136,6 +136,10 @@ fn (mut g Gen) sql_select_expr(node ast.SqlExpr) { g.write(' limit ') g.expr_to_sql(node.limit_expr) } + if node.has_offset { + g.write(' offset ') + g.expr_to_sql(node.offset_expr) + } g.writeln('"));') // Dump all sql parameters generated by our custom expr handler binds := g.sql_buf.str() diff --git a/vlib/v/parser/sql.v b/vlib/v/parser/sql.v index 48f70e6baf..8400cc6b77 100644 --- a/vlib/v/parser/sql.v +++ b/vlib/v/parser/sql.v @@ -40,6 +40,8 @@ fn (mut p Parser) sql_expr() ast.Expr { } mut has_limit := false mut limit_expr := ast.Expr{} + mut has_offset := false + mut offset_expr := ast.Expr{} if p.tok.kind == .name && p.tok.lit == 'limit' { // `limit 1` means that a single object is returned p.check_name() // `limit` @@ -50,6 +52,12 @@ fn (mut p Parser) sql_expr() ast.Expr { } limit_expr = p.expr(0) } + if p.tok.kind == .name && p.tok.lit == 'offset' { + // `limit 1` means that a single object is returned + p.check_name() // `limit` + has_offset = true + offset_expr = p.expr(0) + } if !query_one && !is_count { // return an array typ = table.new_type(p.table.find_or_register_array(table_type, 1, p.mod)) @@ -69,6 +77,8 @@ fn (mut p Parser) sql_expr() ast.Expr { has_where: has_where has_limit: has_limit limit_expr: limit_expr + has_offset: has_offset + offset_expr: offset_expr is_array: !query_one pos: pos }