aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-14 16:10:20 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-14 16:10:20 -0500
commit332741e73980401895e027eb697bb472860036fb (patch)
treeb752539838c2cf3f8a856ab5100f2f043440ac91 /src/test
parent17407a8eaa2afa8ac0de4b0a494f33d8eb7a98bd (diff)
downloadpostgresql-332741e73980401895e027eb697bb472860036fb.tar.gz
postgresql-332741e73980401895e027eb697bb472860036fb.zip
Convert the geometric input functions to report errors softly.
Convert box_in, circle_in, line_in, lseg_in, path_in, point_in, and poly_in to the new style. line_in still throws hard errors for overflows/underflows that can occur when the input is specified as two points rather than in the canonical "Ax + By + C = 0" style. I'm not too concerned about that: it won't be reached in normal dump/restore cases, and it's fairly debatable that such conversion should ever have been made part of a type input function in the first place. But in any case, I don't want to extend the soft error conventions into float.h without more discussion than this patch has had. Amul Sul, minor mods by me Discussion: https://postgr.es/m/CAAJ_b97KeDWUdpTKGOaFYPv0OicjOu6EW+QYWj-Ywrgj_aEy1g@mail.gmail.com
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/box.out25
-rw-r--r--src/test/regress/expected/geometry.out25
-rw-r--r--src/test/regress/expected/line.out61
-rw-r--r--src/test/regress/expected/lseg.out13
-rw-r--r--src/test/regress/expected/path.out25
-rw-r--r--src/test/regress/expected/point.out13
-rw-r--r--src/test/regress/expected/polygon.out25
-rw-r--r--src/test/regress/sql/box.sql6
-rw-r--r--src/test/regress/sql/geometry.sql6
-rw-r--r--src/test/regress/sql/line.sql12
-rw-r--r--src/test/regress/sql/lseg.sql4
-rw-r--r--src/test/regress/sql/path.sql6
-rw-r--r--src/test/regress/sql/point.sql4
-rw-r--r--src/test/regress/sql/polygon.sql6
14 files changed, 231 insertions, 0 deletions
diff --git a/src/test/regress/expected/box.out b/src/test/regress/expected/box.out
index 6bf4d0bdc6d..0d70194def5 100644
--- a/src/test/regress/expected/box.out
+++ b/src/test/regress/expected/box.out
@@ -639,3 +639,28 @@ WHERE seq.id IS NULL OR idx.id IS NULL;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('200', 'box');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('200', 'box');
+ pg_input_error_message
+------------------------------------------
+ invalid input syntax for type box: "200"
+(1 row)
+
+SELECT pg_input_is_valid('((200,300),(500, xyz))', 'box');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('((200,300),(500, xyz))', 'box');
+ pg_input_error_message
+-------------------------------------------------------------
+ invalid input syntax for type box: "((200,300),(500, xyz))"
+(1 row)
+
diff --git a/src/test/regress/expected/geometry.out b/src/test/regress/expected/geometry.out
index b50103b2165..291cacdf4fb 100644
--- a/src/test/regress/expected/geometry.out
+++ b/src/test/regress/expected/geometry.out
@@ -5295,3 +5295,28 @@ SELECT * FROM polygon_tbl WHERE f1 @> '((1,1),(2,2),(2,1))'::polygon
((2,0),(2,4),(0,0))
(1 row)
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('(1', 'circle');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('1,', 'circle');
+ pg_input_error_message
+--------------------------------------------
+ invalid input syntax for type circle: "1,"
+(1 row)
+
+SELECT pg_input_is_valid('(1,2),-1', 'circle');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('(1,2),-1', 'circle');
+ pg_input_error_message
+--------------------------------------------------
+ invalid input syntax for type circle: "(1,2),-1"
+(1 row)
+
diff --git a/src/test/regress/expected/line.out b/src/test/regress/expected/line.out
index fe106589c6a..6baea8fdbdf 100644
--- a/src/test/regress/expected/line.out
+++ b/src/test/regress/expected/line.out
@@ -85,3 +85,64 @@ select '{nan, 1, nan}'::line = '{nan, 1, nan}'::line as true,
t | f
(1 row)
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('{1, 1}', 'line');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('{1, 1}', 'line');
+ pg_input_error_message
+----------------------------------------------
+ invalid input syntax for type line: "{1, 1}"
+(1 row)
+
+SELECT pg_input_is_valid('{0, 0, 0}', 'line');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('{0, 0, 0}', 'line');
+ pg_input_error_message
+---------------------------------------------------------
+ invalid line specification: A and B cannot both be zero
+(1 row)
+
+SELECT pg_input_is_valid('{1, 1, a}', 'line');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('{1, 1, a}', 'line');
+ pg_input_error_message
+-------------------------------------------------
+ invalid input syntax for type line: "{1, 1, a}"
+(1 row)
+
+SELECT pg_input_is_valid('{1, 1, 1e400}', 'line');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('{1, 1, 1e400}', 'line');
+ pg_input_error_message
+---------------------------------------------------
+ "1e400" is out of range for type double precision
+(1 row)
+
+SELECT pg_input_is_valid('(1, 1), (1, 1e400)', 'line');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('(1, 1), (1, 1e400)', 'line');
+ pg_input_error_message
+---------------------------------------------------
+ "1e400" is out of range for type double precision
+(1 row)
+
diff --git a/src/test/regress/expected/lseg.out b/src/test/regress/expected/lseg.out
index 7e878b55779..afb323fe04c 100644
--- a/src/test/regress/expected/lseg.out
+++ b/src/test/regress/expected/lseg.out
@@ -42,3 +42,16 @@ select * from LSEG_TBL;
[(NaN,1),(NaN,90)]
(8 rows)
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('[(1,2),(3)]', 'lseg');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('[(1,2),(3)]', 'lseg');
+ pg_input_error_message
+---------------------------------------------------
+ invalid input syntax for type lseg: "[(1,2),(3)]"
+(1 row)
+
diff --git a/src/test/regress/expected/path.out b/src/test/regress/expected/path.out
index 7ef68d0cd56..529a5e6fc29 100644
--- a/src/test/regress/expected/path.out
+++ b/src/test/regress/expected/path.out
@@ -80,3 +80,28 @@ SELECT popen(f1) AS open_path FROM PATH_TBL;
[(11,12),(13,14)]
(9 rows)
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('[(1,2),(3)]', 'path');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('[(1,2),(3)]', 'path');
+ pg_input_error_message
+---------------------------------------------------
+ invalid input syntax for type path: "[(1,2),(3)]"
+(1 row)
+
+SELECT pg_input_is_valid('[(1,2,6),(3,4,6)]', 'path');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('[(1,2,6),(3,4,6)]', 'path');
+ pg_input_error_message
+---------------------------------------------------------
+ invalid input syntax for type path: "[(1,2,6),(3,4,6)]"
+(1 row)
+
diff --git a/src/test/regress/expected/point.out b/src/test/regress/expected/point.out
index 3bde8ac7d09..a716ceb881b 100644
--- a/src/test/regress/expected/point.out
+++ b/src/test/regress/expected/point.out
@@ -463,3 +463,16 @@ SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000018,0.0000018)'::point;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('1,y', 'point');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('1,y', 'point');
+ pg_input_error_message
+--------------------------------------------
+ invalid input syntax for type point: "1,y"
+(1 row)
+
diff --git a/src/test/regress/expected/polygon.out b/src/test/regress/expected/polygon.out
index 38e433b2ec8..c7d565ad538 100644
--- a/src/test/regress/expected/polygon.out
+++ b/src/test/regress/expected/polygon.out
@@ -306,3 +306,28 @@ WHERE seq.id IS NULL OR idx.id IS NULL;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('(2.0,0.8,0.1)', 'polygon');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('(2.0,0.8,0.1)', 'polygon');
+ pg_input_error_message
+--------------------------------------------------------
+ invalid input syntax for type polygon: "(2.0,0.8,0.1)"
+(1 row)
+
+SELECT pg_input_is_valid('(2.0,xyz)', 'polygon');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('(2.0,xyz)', 'polygon');
+ pg_input_error_message
+----------------------------------------------------
+ invalid input syntax for type polygon: "(2.0,xyz)"
+(1 row)
+
diff --git a/src/test/regress/sql/box.sql b/src/test/regress/sql/box.sql
index ceae58fc02f..02e100391b4 100644
--- a/src/test/regress/sql/box.sql
+++ b/src/test/regress/sql/box.sql
@@ -281,3 +281,9 @@ WHERE seq.id IS NULL OR idx.id IS NULL;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('200', 'box');
+SELECT pg_input_error_message('200', 'box');
+SELECT pg_input_is_valid('((200,300),(500, xyz))', 'box');
+SELECT pg_input_error_message('((200,300),(500, xyz))', 'box');
diff --git a/src/test/regress/sql/geometry.sql b/src/test/regress/sql/geometry.sql
index 8928d04aa3f..309234b76c1 100644
--- a/src/test/regress/sql/geometry.sql
+++ b/src/test/regress/sql/geometry.sql
@@ -523,3 +523,9 @@ SELECT * FROM polygon_tbl WHERE f1 @> '((1,1),(2,2),(2,1))'::polygon
ORDER BY (poly_center(f1))[0];
SELECT * FROM polygon_tbl WHERE f1 @> '((1,1),(2,2),(2,1))'::polygon
ORDER BY (poly_center(f1))[0];
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('(1', 'circle');
+SELECT pg_input_error_message('1,', 'circle');
+SELECT pg_input_is_valid('(1,2),-1', 'circle');
+SELECT pg_input_error_message('(1,2),-1', 'circle');
diff --git a/src/test/regress/sql/line.sql b/src/test/regress/sql/line.sql
index f589ffecc84..f706a41184d 100644
--- a/src/test/regress/sql/line.sql
+++ b/src/test/regress/sql/line.sql
@@ -40,3 +40,15 @@ select * from LINE_TBL;
select '{nan, 1, nan}'::line = '{nan, 1, nan}'::line as true,
'{nan, 1, nan}'::line = '{nan, 2, nan}'::line as false;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('{1, 1}', 'line');
+SELECT pg_input_error_message('{1, 1}', 'line');
+SELECT pg_input_is_valid('{0, 0, 0}', 'line');
+SELECT pg_input_error_message('{0, 0, 0}', 'line');
+SELECT pg_input_is_valid('{1, 1, a}', 'line');
+SELECT pg_input_error_message('{1, 1, a}', 'line');
+SELECT pg_input_is_valid('{1, 1, 1e400}', 'line');
+SELECT pg_input_error_message('{1, 1, 1e400}', 'line');
+SELECT pg_input_is_valid('(1, 1), (1, 1e400)', 'line');
+SELECT pg_input_error_message('(1, 1), (1, 1e400)', 'line');
diff --git a/src/test/regress/sql/lseg.sql b/src/test/regress/sql/lseg.sql
index f266ca3e09e..0fece162e01 100644
--- a/src/test/regress/sql/lseg.sql
+++ b/src/test/regress/sql/lseg.sql
@@ -22,3 +22,7 @@ INSERT INTO LSEG_TBL VALUES ('[(,2),(3,4)]');
INSERT INTO LSEG_TBL VALUES ('[(1,2),(3,4)');
select * from LSEG_TBL;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('[(1,2),(3)]', 'lseg');
+SELECT pg_input_error_message('[(1,2),(3)]', 'lseg');
diff --git a/src/test/regress/sql/path.sql b/src/test/regress/sql/path.sql
index 89f1aa9a329..42c90afe53b 100644
--- a/src/test/regress/sql/path.sql
+++ b/src/test/regress/sql/path.sql
@@ -42,3 +42,9 @@ SELECT f1 AS closed_path FROM PATH_TBL WHERE isclosed(f1);
SELECT pclose(f1) AS closed_path FROM PATH_TBL;
SELECT popen(f1) AS open_path FROM PATH_TBL;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('[(1,2),(3)]', 'path');
+SELECT pg_input_error_message('[(1,2),(3)]', 'path');
+SELECT pg_input_is_valid('[(1,2,6),(3,4,6)]', 'path');
+SELECT pg_input_error_message('[(1,2,6),(3,4,6)]', 'path');
diff --git a/src/test/regress/sql/point.sql b/src/test/regress/sql/point.sql
index 435ff4b9b69..7bd1ebe2b51 100644
--- a/src/test/regress/sql/point.sql
+++ b/src/test/regress/sql/point.sql
@@ -96,3 +96,7 @@ SELECT COUNT(*) FROM point_gist_tbl WHERE f1 ~= '(0.0000018,0.0000018)'::point;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('1,y', 'point');
+SELECT pg_input_error_message('1,y', 'point');
diff --git a/src/test/regress/sql/polygon.sql b/src/test/regress/sql/polygon.sql
index f53b2cb6309..da644e34e30 100644
--- a/src/test/regress/sql/polygon.sql
+++ b/src/test/regress/sql/polygon.sql
@@ -140,3 +140,9 @@ WHERE seq.id IS NULL OR idx.id IS NULL;
RESET enable_seqscan;
RESET enable_indexscan;
RESET enable_bitmapscan;
+
+-- test non-error-throwing API for some core types
+SELECT pg_input_is_valid('(2.0,0.8,0.1)', 'polygon');
+SELECT pg_input_error_message('(2.0,0.8,0.1)', 'polygon');
+SELECT pg_input_is_valid('(2.0,xyz)', 'polygon');
+SELECT pg_input_error_message('(2.0,xyz)', 'polygon');