Skip to content

Commit 0bb49ce

Browse files
authored
feat: Support LOCALTIME and LOCALTIMESTAMP time functions (apache#592)
1 parent bccd63e commit 0bb49ce

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/parser.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ impl<'a> Parser<'a> {
438438
special: true,
439439
}))
440440
}
441-
Keyword::CURRENT_TIMESTAMP | Keyword::CURRENT_TIME | Keyword::CURRENT_DATE => {
441+
Keyword::CURRENT_TIMESTAMP
442+
| Keyword::CURRENT_TIME
443+
| Keyword::CURRENT_DATE
444+
| Keyword::LOCALTIME
445+
| Keyword::LOCALTIMESTAMP => {
442446
self.parse_time_functions(ObjectName(vec![w.to_ident()]))
443447
}
444448
Keyword::CASE => self.parse_case_expr(),

tests/sqlparser_common.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5353,6 +5353,38 @@ fn parse_time_functions() {
53535353

53545354
// Validating Parenthesis
53555355
one_statement_parses_to("SELECT CURRENT_DATE", sql);
5356+
5357+
let sql = "SELECT LOCALTIME()";
5358+
let select = verified_only_select(sql);
5359+
assert_eq!(
5360+
&Expr::Function(Function {
5361+
name: ObjectName(vec![Ident::new("LOCALTIME")]),
5362+
args: vec![],
5363+
over: None,
5364+
distinct: false,
5365+
special: false,
5366+
}),
5367+
expr_from_projection(&select.projection[0])
5368+
);
5369+
5370+
// Validating Parenthesis
5371+
one_statement_parses_to("SELECT LOCALTIME", sql);
5372+
5373+
let sql = "SELECT LOCALTIMESTAMP()";
5374+
let select = verified_only_select(sql);
5375+
assert_eq!(
5376+
&Expr::Function(Function {
5377+
name: ObjectName(vec![Ident::new("LOCALTIMESTAMP")]),
5378+
args: vec![],
5379+
over: None,
5380+
distinct: false,
5381+
special: false,
5382+
}),
5383+
expr_from_projection(&select.projection[0])
5384+
);
5385+
5386+
// Validating Parenthesis
5387+
one_statement_parses_to("SELECT LOCALTIMESTAMP", sql);
53565388
}
53575389

53585390
#[test]

0 commit comments

Comments
 (0)