Support DATETIME keyword (#512)

This commit is contained in:
Yoshiyuki Komazaki 2022-06-05 03:19:57 +09:00 committed by GitHub
parent aa46e930c5
commit d19d955d9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 0 deletions

View file

@ -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"),

View file

@ -169,6 +169,7 @@ define_keywords!(
DATA, DATA,
DATABASE, DATABASE,
DATE, DATE,
DATETIME,
DAY, DAY,
DEALLOCATE, DEALLOCATE,
DEC, DEC,

View file

@ -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) {

View file

@ -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'";