mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-23 07:24:10 +00:00
Postgres: Support INTERVAL
data type options (#1984)
Some checks failed
Rust / compile (push) Has been cancelled
license / Release Audit Tool (RAT) (push) Has been cancelled
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
Some checks failed
Rust / compile (push) Has been cancelled
license / Release Audit Tool (RAT) (push) Has been cancelled
Rust / codestyle (push) Has been cancelled
Rust / lint (push) Has been cancelled
Rust / benchmark-lint (push) Has been cancelled
Rust / docs (push) Has been cancelled
Rust / compile-no-std (push) Has been cancelled
Rust / test (beta) (push) Has been cancelled
Rust / test (nightly) (push) Has been cancelled
Rust / test (stable) (push) Has been cancelled
This commit is contained in:
parent
dd650b88f3
commit
c1648e79fe
9 changed files with 239 additions and 13 deletions
|
@ -961,7 +961,10 @@ fn parse_typed_struct_syntax_bigquery() {
|
|||
})],
|
||||
fields: vec![StructField {
|
||||
field_name: None,
|
||||
field_type: DataType::Interval,
|
||||
field_type: DataType::Interval {
|
||||
fields: None,
|
||||
precision: None
|
||||
},
|
||||
options: None,
|
||||
}]
|
||||
},
|
||||
|
@ -1300,7 +1303,10 @@ fn parse_typed_struct_syntax_bigquery_and_generic() {
|
|||
})],
|
||||
fields: vec![StructField {
|
||||
field_name: None,
|
||||
field_type: DataType::Interval,
|
||||
field_type: DataType::Interval {
|
||||
fields: None,
|
||||
precision: None
|
||||
},
|
||||
options: None,
|
||||
}]
|
||||
},
|
||||
|
|
|
@ -12955,7 +12955,10 @@ fn test_extract_seconds_ok() {
|
|||
expr: Box::new(Expr::Value(
|
||||
(Value::SingleQuotedString("2 seconds".to_string())).with_empty_span()
|
||||
)),
|
||||
data_type: DataType::Interval,
|
||||
data_type: DataType::Interval {
|
||||
fields: None,
|
||||
precision: None
|
||||
},
|
||||
format: None,
|
||||
}),
|
||||
}
|
||||
|
@ -12980,7 +12983,10 @@ fn test_extract_seconds_ok() {
|
|||
expr: Box::new(Expr::Value(
|
||||
(Value::SingleQuotedString("2 seconds".to_string())).with_empty_span(),
|
||||
)),
|
||||
data_type: DataType::Interval,
|
||||
data_type: DataType::Interval {
|
||||
fields: None,
|
||||
precision: None,
|
||||
},
|
||||
format: None,
|
||||
}),
|
||||
})],
|
||||
|
@ -13034,7 +13040,10 @@ fn test_extract_seconds_single_quote_ok() {
|
|||
expr: Box::new(Expr::Value(
|
||||
(Value::SingleQuotedString("2 seconds".to_string())).with_empty_span()
|
||||
)),
|
||||
data_type: DataType::Interval,
|
||||
data_type: DataType::Interval {
|
||||
fields: None,
|
||||
precision: None
|
||||
},
|
||||
format: None,
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -5332,6 +5332,44 @@ fn parse_at_time_zone() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_interval_data_type() {
|
||||
pg_and_generic().verified_stmt("CREATE TABLE t (i INTERVAL)");
|
||||
for p in 0..=6 {
|
||||
pg_and_generic().verified_stmt(&format!("CREATE TABLE t (i INTERVAL({p}))"));
|
||||
pg_and_generic().verified_stmt(&format!("SELECT '1 second'::INTERVAL({p})"));
|
||||
pg_and_generic().verified_stmt(&format!("SELECT CAST('1 second' AS INTERVAL({p}))"));
|
||||
}
|
||||
let fields = [
|
||||
"YEAR",
|
||||
"MONTH",
|
||||
"DAY",
|
||||
"HOUR",
|
||||
"MINUTE",
|
||||
"SECOND",
|
||||
"YEAR TO MONTH",
|
||||
"DAY TO HOUR",
|
||||
"DAY TO MINUTE",
|
||||
"DAY TO SECOND",
|
||||
"HOUR TO MINUTE",
|
||||
"HOUR TO SECOND",
|
||||
"MINUTE TO SECOND",
|
||||
];
|
||||
for field in fields {
|
||||
pg_and_generic().verified_stmt(&format!("CREATE TABLE t (i INTERVAL {field})"));
|
||||
pg_and_generic().verified_stmt(&format!("SELECT '1 second'::INTERVAL {field}"));
|
||||
pg_and_generic().verified_stmt(&format!("SELECT CAST('1 second' AS INTERVAL {field})"));
|
||||
}
|
||||
for p in 0..=6 {
|
||||
for field in fields {
|
||||
pg_and_generic().verified_stmt(&format!("CREATE TABLE t (i INTERVAL {field}({p}))"));
|
||||
pg_and_generic().verified_stmt(&format!("SELECT '1 second'::INTERVAL {field}({p})"));
|
||||
pg_and_generic()
|
||||
.verified_stmt(&format!("SELECT CAST('1 second' AS INTERVAL {field}({p}))"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_create_table_with_options() {
|
||||
let sql = "CREATE TABLE t (c INT) WITH (foo = 'bar', a = 123)";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue