mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-03 13:58:15 +00:00
Support DATETIME
keyword (#512)
This commit is contained in:
parent
aa46e930c5
commit
d19d955d9b
4 changed files with 18 additions and 0 deletions
|
@ -71,6 +71,8 @@ pub enum DataType {
|
||||||
Date,
|
Date,
|
||||||
/// Time
|
/// Time
|
||||||
Time,
|
Time,
|
||||||
|
/// Datetime
|
||||||
|
Datetime,
|
||||||
/// Timestamp
|
/// Timestamp
|
||||||
Timestamp,
|
Timestamp,
|
||||||
/// Interval
|
/// Interval
|
||||||
|
@ -143,6 +145,7 @@ impl fmt::Display for DataType {
|
||||||
DataType::Boolean => write!(f, "BOOLEAN"),
|
DataType::Boolean => write!(f, "BOOLEAN"),
|
||||||
DataType::Date => write!(f, "DATE"),
|
DataType::Date => write!(f, "DATE"),
|
||||||
DataType::Time => write!(f, "TIME"),
|
DataType::Time => write!(f, "TIME"),
|
||||||
|
DataType::Datetime => write!(f, "DATETIME"),
|
||||||
DataType::Timestamp => write!(f, "TIMESTAMP"),
|
DataType::Timestamp => write!(f, "TIMESTAMP"),
|
||||||
DataType::Interval => write!(f, "INTERVAL"),
|
DataType::Interval => write!(f, "INTERVAL"),
|
||||||
DataType::Regclass => write!(f, "REGCLASS"),
|
DataType::Regclass => write!(f, "REGCLASS"),
|
||||||
|
|
|
@ -169,6 +169,7 @@ define_keywords!(
|
||||||
DATA,
|
DATA,
|
||||||
DATABASE,
|
DATABASE,
|
||||||
DATE,
|
DATE,
|
||||||
|
DATETIME,
|
||||||
DAY,
|
DAY,
|
||||||
DEALLOCATE,
|
DEALLOCATE,
|
||||||
DEC,
|
DEC,
|
||||||
|
|
|
@ -2733,6 +2733,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
Keyword::UUID => Ok(DataType::Uuid),
|
Keyword::UUID => Ok(DataType::Uuid),
|
||||||
Keyword::DATE => Ok(DataType::Date),
|
Keyword::DATE => Ok(DataType::Date),
|
||||||
|
Keyword::DATETIME => Ok(DataType::Datetime),
|
||||||
Keyword::TIMESTAMP => {
|
Keyword::TIMESTAMP => {
|
||||||
// TBD: we throw away "with/without timezone" information
|
// TBD: we throw away "with/without timezone" information
|
||||||
if self.parse_keyword(Keyword::WITH) || self.parse_keyword(Keyword::WITHOUT) {
|
if self.parse_keyword(Keyword::WITH) || self.parse_keyword(Keyword::WITHOUT) {
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn parse_literal_timestamp() {
|
fn parse_literal_timestamp() {
|
||||||
let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'";
|
let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue