summaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-12-09 16:07:49 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-12-09 16:07:49 -0500
commitc60488b4748b4316f1c92d62457671046e5c8994 (patch)
tree3868154eb7b042e1fa6bca2e0f581b5c8e28b5b6 /src/test
parent2661469d862239ea8b9e3a1cf5352d833f6f0fec (diff)
Convert datetime input functions to use "soft" error reporting.
This patch converts the input functions for date, time, timetz, timestamp, timestamptz, and interval to the new soft-error style. There's some related stuff in formatting.c that remains to be cleaned up, but that seems like a separable project. Discussion: https://postgr.es/m/3bbbb0df-7382-bf87-9737-340ba096e034@postgrespro.ru
Diffstat (limited to 'src/test')
-rw-r--r--src/test/regress/expected/date.out31
-rw-r--r--src/test/regress/expected/interval.out31
-rw-r--r--src/test/regress/expected/time.out31
-rw-r--r--src/test/regress/expected/timestamp.out31
-rw-r--r--src/test/regress/expected/timestamptz.out31
-rw-r--r--src/test/regress/expected/timetz.out31
-rw-r--r--src/test/regress/sql/date.sql7
-rw-r--r--src/test/regress/sql/interval.sql7
-rw-r--r--src/test/regress/sql/time.sql7
-rw-r--r--src/test/regress/sql/timestamp.sql7
-rw-r--r--src/test/regress/sql/timestamptz.sql7
-rw-r--r--src/test/regress/sql/timetz.sql7
12 files changed, 228 insertions, 0 deletions
diff --git a/src/test/regress/expected/date.out b/src/test/regress/expected/date.out
index 75ff6593789..f8f83e40e95 100644
--- a/src/test/regress/expected/date.out
+++ b/src/test/regress/expected/date.out
@@ -840,6 +840,37 @@ SELECT date '5874898-01-01'; -- out of range
ERROR: date out of range: "5874898-01-01"
LINE 1: SELECT date '5874898-01-01';
^
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'date');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('garbage', 'date');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('6874898-01-01', 'date');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('garbage', 'date');
+ pg_input_error_message
+-----------------------------------------------
+ invalid input syntax for type date: "garbage"
+(1 row)
+
+SELECT pg_input_error_message('6874898-01-01', 'date');
+ pg_input_error_message
+------------------------------------
+ date out of range: "6874898-01-01"
+(1 row)
+
RESET datestyle;
--
-- Simple math
diff --git a/src/test/regress/expected/interval.out b/src/test/regress/expected/interval.out
index 00885acd1df..579e92e7b39 100644
--- a/src/test/regress/expected/interval.out
+++ b/src/test/regress/expected/interval.out
@@ -72,6 +72,37 @@ INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
ERROR: invalid input syntax for type interval: "@ 30 eons ago"
LINE 1: INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
^
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('1.5 weeks', 'interval');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('garbage', 'interval');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('@ 30 eons ago', 'interval');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('garbage', 'interval');
+ pg_input_error_message
+---------------------------------------------------
+ invalid input syntax for type interval: "garbage"
+(1 row)
+
+SELECT pg_input_error_message('@ 30 eons ago', 'interval');
+ pg_input_error_message
+---------------------------------------------------------
+ invalid input syntax for type interval: "@ 30 eons ago"
+(1 row)
+
-- test interval operators
SELECT * FROM INTERVAL_TBL;
f1
diff --git a/src/test/regress/expected/time.out b/src/test/regress/expected/time.out
index f3a71503c25..a44caededd7 100644
--- a/src/test/regress/expected/time.out
+++ b/src/test/regress/expected/time.out
@@ -114,6 +114,37 @@ SELECT '25:00:00'::time; -- not allowed
ERROR: date/time field value out of range: "25:00:00"
LINE 1: SELECT '25:00:00'::time;
^
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('12:00:00', 'time');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('25:00:00', 'time');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('15:36:39 America/New_York', 'time');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('25:00:00', 'time');
+ pg_input_error_message
+------------------------------------------------
+ date/time field value out of range: "25:00:00"
+(1 row)
+
+SELECT pg_input_error_message('15:36:39 America/New_York', 'time');
+ pg_input_error_message
+-----------------------------------------------------------------
+ invalid input syntax for type time: "15:36:39 America/New_York"
+(1 row)
+
--
-- TIME simple math
--
diff --git a/src/test/regress/expected/timestamp.out b/src/test/regress/expected/timestamp.out
index 79f81809558..be66274738e 100644
--- a/src/test/regress/expected/timestamp.out
+++ b/src/test/regress/expected/timestamp.out
@@ -119,6 +119,37 @@ INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/Does_not_exist');
ERROR: time zone "america/does_not_exist" not recognized
LINE 1: INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/D...
^
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'timestamp');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('garbage', 'timestamp');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('garbage', 'timestamp');
+ pg_input_error_message
+----------------------------------------------------
+ invalid input syntax for type timestamp: "garbage"
+(1 row)
+
+SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
+ pg_input_error_message
+--------------------------------------------
+ time zone "nehwon/lankhmar" not recognized
+(1 row)
+
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO TIMESTAMP_TBL VALUES ('Feb 10 17:32:01 1997');
diff --git a/src/test/regress/expected/timestamptz.out b/src/test/regress/expected/timestamptz.out
index eba84191d36..fb06acbccc4 100644
--- a/src/test/regress/expected/timestamptz.out
+++ b/src/test/regress/expected/timestamptz.out
@@ -170,6 +170,37 @@ SELECT '205000-01-10 17:32:01 Europe/Helsinki'::timestamptz; -- non-DST
Fri Jan 10 07:32:01 205000 PST
(1 row)
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'timestamptz');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('garbage', 'timestamptz');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('garbage', 'timestamptz');
+ pg_input_error_message
+-------------------------------------------------------------------
+ invalid input syntax for type timestamp with time zone: "garbage"
+(1 row)
+
+SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
+ pg_input_error_message
+--------------------------------------------
+ time zone "nehwon/lankhmar" not recognized
+(1 row)
+
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-06-10 18:32:01 PDT');
INSERT INTO TIMESTAMPTZ_TBL VALUES ('Feb 10 17:32:01 1997');
diff --git a/src/test/regress/expected/timetz.out b/src/test/regress/expected/timetz.out
index 8942a9b95b6..984285663ba 100644
--- a/src/test/regress/expected/timetz.out
+++ b/src/test/regress/expected/timetz.out
@@ -131,6 +131,37 @@ SELECT '25:00:00 PDT'::timetz; -- not allowed
ERROR: date/time field value out of range: "25:00:00 PDT"
LINE 1: SELECT '25:00:00 PDT'::timetz;
^
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('12:00:00 PDT', 'timetz');
+ pg_input_is_valid
+-------------------
+ t
+(1 row)
+
+SELECT pg_input_is_valid('25:00:00 PDT', 'timetz');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_is_valid('15:36:39 America/New_York', 'timetz');
+ pg_input_is_valid
+-------------------
+ f
+(1 row)
+
+SELECT pg_input_error_message('25:00:00 PDT', 'timetz');
+ pg_input_error_message
+----------------------------------------------------
+ date/time field value out of range: "25:00:00 PDT"
+(1 row)
+
+SELECT pg_input_error_message('15:36:39 America/New_York', 'timetz');
+ pg_input_error_message
+--------------------------------------------------------------------------------
+ invalid input syntax for type time with time zone: "15:36:39 America/New_York"
+(1 row)
+
--
-- TIME simple math
--
diff --git a/src/test/regress/sql/date.sql b/src/test/regress/sql/date.sql
index 8f7435b767c..9fd15be5f98 100644
--- a/src/test/regress/sql/date.sql
+++ b/src/test/regress/sql/date.sql
@@ -193,6 +193,13 @@ SELECT date '4714-11-23 BC'; -- out of range
SELECT date '5874897-12-31';
SELECT date '5874898-01-01'; -- out of range
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'date');
+SELECT pg_input_is_valid('garbage', 'date');
+SELECT pg_input_is_valid('6874898-01-01', 'date');
+SELECT pg_input_error_message('garbage', 'date');
+SELECT pg_input_error_message('6874898-01-01', 'date');
+
RESET datestyle;
--
diff --git a/src/test/regress/sql/interval.sql b/src/test/regress/sql/interval.sql
index 97d33a13236..0517b5b82bd 100644
--- a/src/test/regress/sql/interval.sql
+++ b/src/test/regress/sql/interval.sql
@@ -32,6 +32,13 @@ INSERT INTO INTERVAL_TBL (f1) VALUES ('5 months 12 hours');
INSERT INTO INTERVAL_TBL (f1) VALUES ('badly formatted interval');
INSERT INTO INTERVAL_TBL (f1) VALUES ('@ 30 eons ago');
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('1.5 weeks', 'interval');
+SELECT pg_input_is_valid('garbage', 'interval');
+SELECT pg_input_is_valid('@ 30 eons ago', 'interval');
+SELECT pg_input_error_message('garbage', 'interval');
+SELECT pg_input_error_message('@ 30 eons ago', 'interval');
+
-- test interval operators
SELECT * FROM INTERVAL_TBL;
diff --git a/src/test/regress/sql/time.sql b/src/test/regress/sql/time.sql
index 3637f28798b..b439cd6b41c 100644
--- a/src/test/regress/sql/time.sql
+++ b/src/test/regress/sql/time.sql
@@ -40,6 +40,13 @@ SELECT '23:59:60.01'::time; -- not allowed
SELECT '24:01:00'::time; -- not allowed
SELECT '25:00:00'::time; -- not allowed
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('12:00:00', 'time');
+SELECT pg_input_is_valid('25:00:00', 'time');
+SELECT pg_input_is_valid('15:36:39 America/New_York', 'time');
+SELECT pg_input_error_message('25:00:00', 'time');
+SELECT pg_input_error_message('15:36:39 America/New_York', 'time');
+
--
-- TIME simple math
--
diff --git a/src/test/regress/sql/timestamp.sql b/src/test/regress/sql/timestamp.sql
index ebc969f36cf..e1175b12ce2 100644
--- a/src/test/regress/sql/timestamp.sql
+++ b/src/test/regress/sql/timestamp.sql
@@ -94,6 +94,13 @@ INSERT INTO TIMESTAMP_TBL VALUES ('19970210 173201 America/New_York');
-- this fails (even though TZ is a no-op, we still look it up)
INSERT INTO TIMESTAMP_TBL VALUES ('19970710 173201 America/Does_not_exist');
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'timestamp');
+SELECT pg_input_is_valid('garbage', 'timestamp');
+SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
+SELECT pg_input_error_message('garbage', 'timestamp');
+SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamp');
+
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMP_TBL VALUES ('1997-06-10 18:32:01 PDT');
diff --git a/src/test/regress/sql/timestamptz.sql b/src/test/regress/sql/timestamptz.sql
index a107abc5a4c..27263b3e0bb 100644
--- a/src/test/regress/sql/timestamptz.sql
+++ b/src/test/regress/sql/timestamptz.sql
@@ -107,6 +107,13 @@ SELECT '20500110 173201 Europe/Helsinki'::timestamptz; -- non-DST
SELECT '205000-07-10 17:32:01 Europe/Helsinki'::timestamptz; -- DST
SELECT '205000-01-10 17:32:01 Europe/Helsinki'::timestamptz; -- non-DST
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('now', 'timestamptz');
+SELECT pg_input_is_valid('garbage', 'timestamptz');
+SELECT pg_input_is_valid('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
+SELECT pg_input_error_message('garbage', 'timestamptz');
+SELECT pg_input_error_message('2001-01-01 00:00 Nehwon/Lankhmar', 'timestamptz');
+
-- Check date conversion and date arithmetic
INSERT INTO TIMESTAMPTZ_TBL VALUES ('1997-06-10 18:32:01 PDT');
diff --git a/src/test/regress/sql/timetz.sql b/src/test/regress/sql/timetz.sql
index 7b70f4656c9..b62aa3fe057 100644
--- a/src/test/regress/sql/timetz.sql
+++ b/src/test/regress/sql/timetz.sql
@@ -45,6 +45,13 @@ SELECT '23:59:60.01 PDT'::timetz; -- not allowed
SELECT '24:01:00 PDT'::timetz; -- not allowed
SELECT '25:00:00 PDT'::timetz; -- not allowed
+-- Test non-error-throwing API
+SELECT pg_input_is_valid('12:00:00 PDT', 'timetz');
+SELECT pg_input_is_valid('25:00:00 PDT', 'timetz');
+SELECT pg_input_is_valid('15:36:39 America/New_York', 'timetz');
+SELECT pg_input_error_message('25:00:00 PDT', 'timetz');
+SELECT pg_input_error_message('15:36:39 America/New_York', 'timetz');
+
--
-- TIME simple math
--