Implement TRY_CAST (#299)

Adds support for `TRY_CAST` and fixes a clippy error
This commit is contained in:
Mike Seddon 2021-03-22 09:26:16 +11:00 committed by GitHub
parent 43fef23bc8
commit e6e37b47db
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 59 additions and 7 deletions

View file

@ -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(