Add LIMIT as RESERVED_FOR_TABLE_ALIAS, this closes Issue#67

This commit is contained in:
Jovansonlee Cesar 2019-05-18 10:53:19 +08:00
parent 908082d26f
commit d263d285e2
3 changed files with 11 additions and 2 deletions

View file

@ -393,7 +393,7 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[&str] = &[
// Reserved as both a table and a column alias:
WITH, SELECT, WHERE, GROUP, ORDER, UNION, EXCEPT, INTERSECT,
// Reserved only as a table alias in the `FROM`/`JOIN` clauses:
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING,
ON, JOIN, INNER, CROSS, FULL, LEFT, RIGHT, NATURAL, USING, LIMIT,
];
/// Can't be used as a column alias, so that `SELECT <expr> alias`

View file

@ -1202,7 +1202,6 @@ impl Parser {
} else {
None
};
let limit = if self.parse_keyword("LIMIT") {
self.parse_limit()?
} else {

View file

@ -124,6 +124,16 @@ fn parse_simple_select() {
assert_eq!(Some(ASTNode::SQLValue(Value::Long(5))), select.limit);
}
#[test]
fn parse_select_with_limit_but_no_where() {
let sql = "SELECT id, fname, lname FROM customer LIMIT 5";
let select = verified_only_select(sql);
assert_eq!(false, select.distinct);
assert_eq!(3, select.projection.len());
let select = verified_query(sql);
assert_eq!(Some(ASTNode::SQLValue(Value::Long(5))), select.limit);
}
#[test]
fn parse_select_distinct() {
let sql = "SELECT DISTINCT name FROM customer";