45 lines
746 B
SQL
45 lines
746 B
SQL
# name: test/sql/cast/test_try_cast.test
|
|
# description: Test try cast
|
|
# group: [cast]
|
|
|
|
statement ok
|
|
PRAGMA enable_verification
|
|
|
|
# TRY_CAST turns a failed cast into NULL
|
|
query I
|
|
SELECT TRY_CAST('hello' as INTEGER)
|
|
----
|
|
NULL
|
|
|
|
# CAST throws an error
|
|
statement error
|
|
SELECT CAST('hello' as INTEGER)
|
|
----
|
|
|
|
query IIII
|
|
SELECT TRY_CAST(3 as BIGINT), CAST(3 AS BIGINT), TRY_CAST(2 as BIGINT), CAST(3 AS INTEGER)
|
|
----
|
|
3 3 2 3
|
|
|
|
# not a reserved keyword
|
|
statement ok
|
|
CREATE TABLE try_cast(try_cast INTEGER);
|
|
|
|
statement ok
|
|
INSERT INTO try_cast VALUES (3);
|
|
|
|
query I
|
|
SELECT try_cast FROM try_cast;
|
|
----
|
|
3
|
|
|
|
query I
|
|
SELECT try_cast(try_cast as bigint) FROM try_cast;
|
|
----
|
|
3
|
|
|
|
query I
|
|
SELECT try_cast(try_cast(try_cast as integer) as integer) FROM try_cast;
|
|
----
|
|
3
|