Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ pub enum DataType {
Time,
/// Datetime
Datetime,
/// Timestamp
/// Timestamp [Without Time Zone]
Timestamp,
/// Timestamp With Time Zone
TimestampTz,
/// Interval
Interval,
/// Regclass used in postgresql serial
Expand Down Expand Up @@ -157,6 +159,7 @@ impl fmt::Display for DataType {
DataType::Time => write!(f, "TIME"),
DataType::Datetime => write!(f, "DATETIME"),
DataType::Timestamp => write!(f, "TIMESTAMP"),
DataType::TimestampTz => write!(f, "TIMESTAMPTZ"),
Comment on lines 161 to +162
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add DataType::TimestampTz

DataType::Interval => write!(f, "INTERVAL"),
DataType::Regclass => write!(f, "REGCLASS"),
DataType::Text => write!(f, "TEXT"),
Expand Down
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,7 @@ define_keywords!(
TIES,
TIME,
TIMESTAMP,
TIMESTAMPTZ,
TIMEZONE,
TIMEZONE_HOUR,
TIMEZONE_MINUTE,
Expand Down
11 changes: 8 additions & 3 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3119,12 +3119,17 @@ impl<'a> Parser<'a> {
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) {
if self.parse_keyword(Keyword::WITH) {
self.expect_keywords(&[Keyword::TIME, Keyword::ZONE])?;
Ok(DataType::TimestampTz)
} else if self.parse_keyword(Keyword::WITHOUT) {
self.expect_keywords(&[Keyword::TIME, Keyword::ZONE])?;
Ok(DataType::Timestamp)
} else {
Ok(DataType::Timestamp)
}
Ok(DataType::Timestamp)
}
Comment on lines -3123 to 3131
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable with time zone and without time zone

Keyword::TIMESTAMPTZ => Ok(DataType::TimestampTz),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add TimestampTz into parser

Keyword::TIME => {
// TBD: we throw away "with/without timezone" information
if self.parse_keyword(Keyword::WITH) || self.parse_keyword(Keyword::WITHOUT) {
Expand Down
25 changes: 24 additions & 1 deletion tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2854,7 +2854,7 @@ fn parse_literal_datetime() {
}

#[test]
fn parse_literal_timestamp() {
fn parse_literal_timestamp_without_time_zone() {
let sql = "SELECT TIMESTAMP '1999-01-01 01:23:34'";
let select = verified_only_select(sql);
assert_eq!(
Expand All @@ -2864,6 +2864,29 @@ fn parse_literal_timestamp() {
},
expr_from_projection(only(&select.projection)),
);

one_statement_parses_to(
"SELECT TIMESTAMP WITHOUT TIME ZONE '1999-01-01 01:23:34'",
sql,
);
}

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

one_statement_parses_to(
"SELECT TIMESTAMP WITH TIME ZONE '1999-01-01 01:23:34Z'",
sql,
);
}

#[test]
Expand Down