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
6 changes: 4 additions & 2 deletions src/ast/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ pub enum DataType {
/// Databricks timestamp without time zone. See [1].
///
/// [1]: https://docs.databricks.com/aws/en/sql/language-manual/data-types/timestamp-ntz-type
TimestampNtz,
TimestampNtz(Option<u64>),
/// Interval type.
Interval {
/// [PostgreSQL] fields specification like `INTERVAL YEAR TO MONTH`.
Expand Down Expand Up @@ -676,7 +676,9 @@ impl fmt::Display for DataType {
DataType::Timestamp(precision, timezone_info) => {
format_datetime_precision_and_tz(f, "TIMESTAMP", precision, timezone_info)
}
DataType::TimestampNtz => write!(f, "TIMESTAMP_NTZ"),
DataType::TimestampNtz(precision) => {
format_type_with_optional_length(f, "TIMESTAMP_NTZ", precision, false)
}
DataType::Datetime64(precision, timezone) => {
format_clickhouse_datetime_precision_and_timezone(
f,
Expand Down
4 changes: 3 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10542,7 +10542,9 @@ impl<'a> Parser<'a> {
self.parse_optional_precision()?,
TimezoneInfo::Tz,
)),
Keyword::TIMESTAMP_NTZ => Ok(DataType::TimestampNtz),
Keyword::TIMESTAMP_NTZ => {
Ok(DataType::TimestampNtz(self.parse_optional_precision()?))
}
Keyword::TIME => {
let precision = self.parse_optional_precision()?;
let tz = if self.parse_keyword(Keyword::WITH) {
Expand Down
6 changes: 3 additions & 3 deletions tests/sqlparser_databricks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ fn data_type_timestamp_ntz() {
assert_eq!(
databricks().verified_expr("TIMESTAMP_NTZ '2025-03-29T18:52:00'"),
Expr::TypedString(TypedString {
data_type: DataType::TimestampNtz,
data_type: DataType::TimestampNtz(None),
value: ValueWithSpan {
value: Value::SingleQuotedString("2025-03-29T18:52:00".to_owned()),
span: Span::empty(),
Expand All @@ -345,7 +345,7 @@ fn data_type_timestamp_ntz() {
expr: Box::new(Expr::Nested(Box::new(Expr::Identifier(
"created_at".into()
)))),
data_type: DataType::TimestampNtz,
data_type: DataType::TimestampNtz(None),
format: None
}
);
Expand All @@ -357,7 +357,7 @@ fn data_type_timestamp_ntz() {
columns,
vec![ColumnDef {
name: "x".into(),
data_type: DataType::TimestampNtz,
data_type: DataType::TimestampNtz(None),
options: vec![],
}]
);
Expand Down
15 changes: 15 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4638,6 +4638,21 @@ fn test_create_database() {
assert!(err.contains("Expected"), "Unexpected error: {err}");
}

#[test]
fn test_timestamp_ntz_with_precision() {
snowflake().verified_stmt("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(1))");
snowflake().verified_stmt("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(9))");

let select =
snowflake().verified_only_select("SELECT CAST('2024-01-01 01:00:00' AS TIMESTAMP_NTZ(9))");
match expr_from_projection(only(&select.projection)) {
Expr::Cast { data_type, .. } => {
assert_eq!(*data_type, DataType::TimestampNtz(Some(9)));
}
_ => unreachable!(),
}
}

#[test]
fn test_drop_constraints() {
snowflake().verified_stmt("ALTER TABLE tbl DROP PRIMARY KEY");
Expand Down
Loading