aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-15 12:18:36 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-15 12:18:36 -0500
commitd35a1af468162f510b6139bf81a7a41fd8ba8500 (patch)
tree26c76daf21e73a9ed1e64eb534cf9296370ca4b2 /src/test
parent75f49221c22286104f032827359783aa5f4e6646 (diff)
downloadpostgresql-d35a1af468162f510b6139bf81a7a41fd8ba8500.tar.gz
postgresql-d35a1af468162f510b6139bf81a7a41fd8ba8500.zip
Convert range_in and multirange_in to report errors softly.
This is mostly straightforward, except that if the range type has a canonical function, that might throw an error during range input. (Such errors probably only occur for edge cases: in the in-core canonical functions, it happens only if a bound has the maximum valid value for the underlying type.) Hence, this patch extends the soft-error regime to allow canonical functions to return errors softly as well. Extensions implementing range canonical functions will need modification anyway because of the API change for range_serialize(); while at it, they might want to do something similar to what's been done here in the in-core canonical functions. Discussion: https://postgr.es/m/3284599.1671075185@sss.pgh.pa.us
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/multirangetypes.out31
-rw-r--r--src/test/regress/expected/rangetypes.out67
-rw-r--r--src/test/regress/sql/multirangetypes.sql7
-rw-r--r--src/test/regress/sql/rangetypes.sql13
4 files changed, 118 insertions, 0 deletions
diff --git a/src/test/regress/expected/multirangetypes.out b/src/test/regress/expected/multirangetypes.out
index ac2eb84c3af..14aa4c46cde 100644
--- a/src/test/regress/expected/multirangetypes.out
+++ b/src/test/regress/expected/multirangetypes.out
@@ -274,6 +274,37 @@ select '{(a,a)}'::textmultirange;
{}
(1 row)
+-- Also try it with non-error-throwing API
+select pg_input_is_valid('{[1,2], [4,5]}', 'int4multirange');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+select pg_input_is_valid('{[1,2], [4,5]', 'int4multirange');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('{[1,2], [4,5]', 'int4multirange');
+ pg_input_error_message
+-----------------------------------------------
+ malformed multirange literal: "{[1,2], [4,5]"
+(1 row)
+
+select pg_input_is_valid('{[1,2], [4,zed]}', 'int4multirange');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('{[1,2], [4,zed]}', 'int4multirange');
+ pg_input_error_message
+----------------------------------------------
+ invalid input syntax for type integer: "zed"
+(1 row)
+
--
-- test the constructor
---
diff --git a/src/test/regress/expected/rangetypes.out b/src/test/regress/expected/rangetypes.out
index 04ccd5d451e..9eb31aecfe1 100644
--- a/src/test/regress/expected/rangetypes.out
+++ b/src/test/regress/expected/rangetypes.out
@@ -175,6 +175,73 @@ select '(a,a)'::textrange;
empty
(1 row)
+-- Also try it with non-error-throwing API
+select pg_input_is_valid('(1,4)', 'int4range');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+select pg_input_is_valid('(1,4', 'int4range');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('(1,4', 'int4range');
+ pg_input_error_message
+---------------------------------
+ malformed range literal: "(1,4"
+(1 row)
+
+select pg_input_is_valid('(4,1)', 'int4range');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('(4,1)', 'int4range');
+ pg_input_error_message
+-------------------------------------------------------------------
+ range lower bound must be less than or equal to range upper bound
+(1 row)
+
+select pg_input_is_valid('(4,zed)', 'int4range');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('(4,zed)', 'int4range');
+ pg_input_error_message
+----------------------------------------------
+ invalid input syntax for type integer: "zed"
+(1 row)
+
+select pg_input_is_valid('[1,2147483647]', 'int4range');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('[1,2147483647]', 'int4range');
+ pg_input_error_message
+------------------------
+ integer out of range
+(1 row)
+
+select pg_input_is_valid('[2000-01-01,5874897-12-31]', 'daterange');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+select pg_input_error_message('[2000-01-01,5874897-12-31]', 'daterange');
+ pg_input_error_message
+------------------------
+ date out of range
+(1 row)
+
--
-- create some test data and test the operators
--
diff --git a/src/test/regress/sql/multirangetypes.sql b/src/test/regress/sql/multirangetypes.sql
index 1abcaeddb5c..78a650eb0fb 100644
--- a/src/test/regress/sql/multirangetypes.sql
+++ b/src/test/regress/sql/multirangetypes.sql
@@ -58,6 +58,13 @@ select '{[a,a)}'::textmultirange;
select '{(a,a]}'::textmultirange;
select '{(a,a)}'::textmultirange;
+-- Also try it with non-error-throwing API
+select pg_input_is_valid('{[1,2], [4,5]}', 'int4multirange');
+select pg_input_is_valid('{[1,2], [4,5]', 'int4multirange');
+select pg_input_error_message('{[1,2], [4,5]', 'int4multirange');
+select pg_input_is_valid('{[1,2], [4,zed]}', 'int4multirange');
+select pg_input_error_message('{[1,2], [4,zed]}', 'int4multirange');
+
--
-- test the constructor
---
diff --git a/src/test/regress/sql/rangetypes.sql b/src/test/regress/sql/rangetypes.sql
index 1a10f67f199..798cd239103 100644
--- a/src/test/regress/sql/rangetypes.sql
+++ b/src/test/regress/sql/rangetypes.sql
@@ -40,6 +40,19 @@ select '[a,a)'::textrange;
select '(a,a]'::textrange;
select '(a,a)'::textrange;
+-- Also try it with non-error-throwing API
+select pg_input_is_valid('(1,4)', 'int4range');
+select pg_input_is_valid('(1,4', 'int4range');
+select pg_input_error_message('(1,4', 'int4range');
+select pg_input_is_valid('(4,1)', 'int4range');
+select pg_input_error_message('(4,1)', 'int4range');
+select pg_input_is_valid('(4,zed)', 'int4range');
+select pg_input_error_message('(4,zed)', 'int4range');
+select pg_input_is_valid('[1,2147483647]', 'int4range');
+select pg_input_error_message('[1,2147483647]', 'int4range');
+select pg_input_is_valid('[2000-01-01,5874897-12-31]', 'daterange');
+select pg_input_error_message('[2000-01-01,5874897-12-31]', 'daterange');
+
--
-- create some test data and test the operators
--