From 90bf691d2af7fadb08ef68680e889fe7638deb39 Mon Sep 17 00:00:00 2001 From: Vladimir Rachkin Date: Thu, 21 Nov 2024 18:25:44 +0300 Subject: [PATCH] Add regression test for TRY_CAST --- src/test/regress/expected/try_cast.out | 47 ++++++++++++++++++++++++++ src/test/regress/sql/try_cast.sql | 19 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/test/regress/expected/try_cast.out create mode 100644 src/test/regress/sql/try_cast.sql diff --git a/src/test/regress/expected/try_cast.out b/src/test/regress/expected/try_cast.out new file mode 100644 index 0000000000..0a938a4532 --- /dev/null +++ b/src/test/regress/expected/try_cast.out @@ -0,0 +1,47 @@ +create schema trycast; +set search_path = trycast; + +-- no way to cast +select try_cast(12 as date); + date +------ + +(1 row) + +-- typecast via I/O +select try_cast('11/11/20111' as int); + int4 +------ + +(1 row) +select try_cast('111d' as int); + int4 +------ + +(1 row) + +-- typecast from pg_proc +select try_cast('112344466343'::int8 as int4); + int4 +------ + +(1 row) + +-- arrays +select try_cast('{1, 2, 31111111111}'::int8[] as int4[]); -- pg_proc + int4 +------ + {1,2,NULL} +(1 row) +select try_cast('{1, 2, lol}'::text[] as int4[]); -- via I/O + int4 +------ + {1,2,NULL} +(1 row) +select try_cast('{1, 2, 31111111111}' as int4[]); -- + int4 +------ + {1,2,NULL} +(1 row) + +reset search_path; \ No newline at end of file diff --git a/src/test/regress/sql/try_cast.sql b/src/test/regress/sql/try_cast.sql new file mode 100644 index 0000000000..58276c4b39 --- /dev/null +++ b/src/test/regress/sql/try_cast.sql @@ -0,0 +1,19 @@ +create schema trycast; +set search_path = trycast; + +-- no way to cast +select try_cast(12 as date); + +-- typecast via I/O +select try_cast('11/11/20111' as int); +select try_cast('111d' as int); + +-- typecast from pg_proc +select try_cast('112344466343'::int8 as int4); + +-- arrays +select try_cast('{1, 2, 31111111111}'::int8[] as int4[]); -- pg_proc +select try_cast('{1, 2, lol}'::text[] as int4[]); -- via I/O +select try_cast('{1, 2, 31111111111}' as int4[]); -- + +reset search_path; \ No newline at end of file