Allow LIMIT/OFFSET/FETCH without FROM

Postgres allows it, as does ANSI SQL per the <query expression> definition:
https://jakewheat.github.io/sql-overview/sql-2011-foundation-grammar.html#_7_13_query_expression
This commit is contained in:
Nickolay Ponomarev 2019-06-17 00:54:37 +03:00
parent c1509b36ec
commit d60bdc0b92
2 changed files with 10 additions and 3 deletions

View file

@ -216,6 +216,9 @@ fn parse_limit_is_not_an_alias() {
// In dialects supporting LIMIT it shouldn't be parsed as a table alias
let ast = verified_query("SELECT id FROM customer LIMIT 1");
assert_eq!(Some(ASTNode::SQLValue(Value::Long(1))), ast.limit);
let ast = verified_query("SELECT 1 LIMIT 5");
assert_eq!(Some(ASTNode::SQLValue(Value::Long(5))), ast.limit);
}
#[test]
@ -2194,6 +2197,8 @@ fn parse_offset() {
},
_ => panic!("Test broke"),
}
let ast = verified_query("SELECT 'foo' OFFSET 0 ROWS");
assert_eq!(ast.offset, Some(ASTNode::SQLValue(Value::Long(0))));
}
#[test]
@ -2213,6 +2218,8 @@ fn parse_fetch() {
};
let ast = verified_query("SELECT foo FROM bar FETCH FIRST 2 ROWS ONLY");
assert_eq!(ast.fetch, Some(FETCH_FIRST_TWO_ROWS_ONLY));
let ast = verified_query("SELECT 'foo' FETCH FIRST 2 ROWS ONLY");
assert_eq!(ast.fetch, Some(FETCH_FIRST_TWO_ROWS_ONLY));
let ast = verified_query("SELECT foo FROM bar FETCH FIRST ROWS ONLY");
assert_eq!(
ast.fetch,