Skip to content

Commit

Permalink
Update try_convert tests
Browse files Browse the repository at this point in the history
  • Loading branch information
robozmey committed Nov 26, 2024
1 parent 7314267 commit 92e8529
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
33 changes: 33 additions & 0 deletions src/test/regress/expected/try_convert.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
create schema tryconvert;
set search_path = tryconvert;
-- start_ignore
CREATE EXTENSION IF NOT EXISTS try_convert;
-- end_ignore
-- not date
select try_convert('12', '2002-10-26'::date);
try_convert
-------------

(1 row)

-- not int
select try_convert('11/11/20111', 0::int);
try_convert
-------------

(1 row)

select try_convert('111d', 0::int);
try_convert
-------------

(1 row)

-- to big for int2
select try_convert('112344466343', 0::int2);
try_convert
-------------

(1 row)

reset search_path;
19 changes: 7 additions & 12 deletions src/test/regress/sql/try_convert.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ set search_path = tryconvert;
CREATE EXTENSION IF NOT EXISTS try_convert;
-- end_ignore

-- no way to convert
select try_convert(12::text, NULL::date);
-- not date
select try_convert('12', '2002-10-26'::date);

-- typecast via I/O
select try_convert('11/11/20111', NULL::int);
select try_convert('111d', NULL::int);
-- not int
select try_convert('11/11/20111', 0::int);
select try_convert('111d', 0::int);

-- typecast from pg_proc
select try_convert('112344466343', NULL::int4);

-- arrays
select try_convert('{1, 2, 31111111111}', NULL::int4[]); -- pg_proc
select try_convert('{1, 2, lol}', NULL::int4[]); -- via I/O
select try_convert('{1, 2, 31111111111}', NULL::int4[]); --
-- to big for int2
select try_convert('112344466343', 0::int2);

reset search_path;

0 comments on commit 92e8529

Please sign in to comment.