Skip to content

Commit

Permalink
Add regression test for TRY_CAST
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Nov 21, 2024
1 parent 389ef57 commit 90bf691
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/test/regress/expected/try_cast.out
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 19 additions & 0 deletions src/test/regress/sql/try_cast.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 90bf691

Please sign in to comment.