Skip to content

Commit

Permalink
feat: Support LOCALTIME and LOCALTIMESTAMP time functions
Browse files Browse the repository at this point in the history
  • Loading branch information
MazterQyou committed Aug 24, 2022
1 parent ca8131c commit e9f7462
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,11 @@ impl<'a> Parser<'a> {
special: true,
}))
}
Keyword::CURRENT_TIMESTAMP | Keyword::CURRENT_TIME | Keyword::CURRENT_DATE => {
Keyword::CURRENT_TIMESTAMP
| Keyword::CURRENT_TIME
| Keyword::CURRENT_DATE
| Keyword::LOCALTIME
| Keyword::LOCALTIMESTAMP => {
self.parse_time_functions(ObjectName(vec![w.to_ident()]))
}
Keyword::CASE => self.parse_case_expr(),
Expand Down
32 changes: 32 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4739,6 +4739,38 @@ fn parse_time_functions() {

// Validating Parenthesis
one_statement_parses_to("SELECT CURRENT_DATE", sql);

let sql = "SELECT LOCALTIME()";
let select = verified_only_select(sql);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("LOCALTIME")]),
args: vec![],
over: None,
distinct: false,
special: false,
}),
expr_from_projection(&select.projection[0])
);

// Validating Parenthesis
one_statement_parses_to("SELECT LOCALTIME", sql);

let sql = "SELECT LOCALTIMESTAMP()";
let select = verified_only_select(sql);
assert_eq!(
&Expr::Function(Function {
name: ObjectName(vec![Ident::new("LOCALTIMESTAMP")]),
args: vec![],
over: None,
distinct: false,
special: false,
}),
expr_from_projection(&select.projection[0])
);

// Validating Parenthesis
one_statement_parses_to("SELECT LOCALTIMESTAMP", sql);
}

#[test]
Expand Down

0 comments on commit e9f7462

Please sign in to comment.