Skip to content

Commit

Permalink
Support DATETIME keyword (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
komukomo committed Jun 4, 2022
1 parent aa46e93 commit d19d955
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/ast/data_type.rs
Expand Up @@ -71,6 +71,8 @@ pub enum DataType {
Date,
/// Time
Time,
/// Datetime
Datetime,
/// Timestamp
Timestamp,
/// Interval
Expand Down Expand Up @@ -143,6 +145,7 @@ impl fmt::Display for DataType {
DataType::Boolean => write!(f, "BOOLEAN"),
DataType::Date => write!(f, "DATE"),
DataType::Time => write!(f, "TIME"),
DataType::Datetime => write!(f, "DATETIME"),
DataType::Timestamp => write!(f, "TIMESTAMP"),
DataType::Interval => write!(f, "INTERVAL"),
DataType::Regclass => write!(f, "REGCLASS"),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Expand Up @@ -169,6 +169,7 @@ define_keywords!(
DATA,
DATABASE,
DATE,
DATETIME,
DAY,
DEALLOCATE,
DEC,
Expand Down
1 change: 1 addition & 0 deletions src/parser.rs
Expand Up @@ -2733,6 +2733,7 @@ impl<'a> Parser<'a> {
}
Keyword::UUID => Ok(DataType::Uuid),
Keyword::DATE => Ok(DataType::Date),
Keyword::DATETIME => Ok(DataType::Datetime),
Keyword::TIMESTAMP => {
// TBD: we throw away "with/without timezone" information
if self.parse_keyword(Keyword::WITH) || self.parse_keyword(Keyword::WITHOUT) {
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_common.rs
Expand Up @@ -2615,6 +2615,19 @@ fn parse_literal_time() {
);
}

#[test]
fn parse_literal_datetime() {
let sql = "SELECT DATETIME '1999-01-01 01:23:34.45'";
let select = verified_only_select(sql);
assert_eq!(
&Expr::TypedString {
data_type: DataType::Datetime,
value: "1999-01-01 01:23:34.45".into()
},
expr_from_projection(only(&select.projection)),
);
}

#[test]
fn parse_literal_timestamp() {
let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'";
Expand Down

0 comments on commit d19d955

Please sign in to comment.