Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support DATETIME keyword #512

Merged
merged 1 commit into from Jun 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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