mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-30 10:47:22 +00:00
Implement TRY_CAST (#299)
Adds support for `TRY_CAST` and fixes a clippy error
This commit is contained in:
parent
43fef23bc8
commit
e6e37b47db
5 changed files with 59 additions and 7 deletions
|
@ -981,6 +981,35 @@ fn parse_cast() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_try_cast() {
|
||||
let sql = "SELECT TRY_CAST(id AS BIGINT) FROM customer";
|
||||
let select = verified_only_select(sql);
|
||||
assert_eq!(
|
||||
&Expr::TryCast {
|
||||
expr: Box::new(Expr::Identifier(Ident::new("id"))),
|
||||
data_type: DataType::BigInt
|
||||
},
|
||||
expr_from_projection(only(&select.projection))
|
||||
);
|
||||
one_statement_parses_to(
|
||||
"SELECT TRY_CAST(id AS BIGINT) FROM customer",
|
||||
"SELECT TRY_CAST(id AS BIGINT) FROM customer",
|
||||
);
|
||||
|
||||
verified_stmt("SELECT TRY_CAST(id AS NUMERIC) FROM customer");
|
||||
|
||||
one_statement_parses_to(
|
||||
"SELECT TRY_CAST(id AS DEC) FROM customer",
|
||||
"SELECT TRY_CAST(id AS NUMERIC) FROM customer",
|
||||
);
|
||||
|
||||
one_statement_parses_to(
|
||||
"SELECT TRY_CAST(id AS DECIMAL) FROM customer",
|
||||
"SELECT TRY_CAST(id AS NUMERIC) FROM customer",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_extract() {
|
||||
let sql = "SELECT EXTRACT(YEAR FROM d)";
|
||||
|
@ -1224,6 +1253,7 @@ fn parse_assert() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
#[allow(clippy::collapsible_match)]
|
||||
fn parse_assert_message() {
|
||||
let sql = "ASSERT (SELECT COUNT(*) FROM my_table) > 0 AS 'No rows in my_table'";
|
||||
let ast = one_statement_parses_to(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue