4 CREATE TABLE TIME_TBL (f1 time(2));
5 INSERT INTO TIME_TBL VALUES ('00:00');
6 INSERT INTO TIME_TBL VALUES ('01:00');
7 -- as of 7.4, timezone spec should be accepted and ignored
8 INSERT INTO TIME_TBL VALUES ('02:03 PST');
9 INSERT INTO TIME_TBL VALUES ('11:59 EDT');
10 INSERT INTO TIME_TBL VALUES ('12:00');
11 INSERT INTO TIME_TBL VALUES ('12:01');
12 INSERT INTO TIME_TBL VALUES ('23:59');
13 INSERT INTO TIME_TBL VALUES ('11:59:59.99 PM');
14 INSERT INTO TIME_TBL VALUES ('2003-03-07 15:36:39 America/New_York');
15 INSERT INTO TIME_TBL VALUES ('2003-07-07 15:36:39 America/New_York');
16 -- this should fail (the timezone offset is not known)
17 INSERT INTO TIME_TBL VALUES ('15:36:39 America/New_York');
18 ERROR: invalid input syntax for type time: "15:36:39 America/New_York"
19 LINE 1: INSERT INTO TIME_TBL VALUES ('15:36:39 America/New_York');
21 SELECT f1 AS "Time" FROM TIME_TBL;
36 SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
44 SELECT f1 AS "Five" FROM TIME_TBL WHERE f1 > '05:06:07';
56 SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
61 SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
77 SELECT '23:59:59.999999'::time;
83 SELECT '23:59:59.9999999'::time; -- rounds up
89 SELECT '23:59:60'::time; -- rounds up
95 SELECT '24:00:00'::time; -- allowed
101 SELECT '24:00:00.01'::time; -- not allowed
102 ERROR: date/time field value out of range: "24:00:00.01"
103 LINE 1: SELECT '24:00:00.01'::time;
105 SELECT '23:59:60.01'::time; -- not allowed
106 ERROR: date/time field value out of range: "23:59:60.01"
107 LINE 1: SELECT '23:59:60.01'::time;
109 SELECT '24:01:00'::time; -- not allowed
110 ERROR: date/time field value out of range: "24:01:00"
111 LINE 1: SELECT '24:01:00'::time;
113 SELECT '25:00:00'::time; -- not allowed
114 ERROR: date/time field value out of range: "25:00:00"
115 LINE 1: SELECT '25:00:00'::time;
117 -- Test non-error-throwing API
118 SELECT pg_input_is_valid('12:00:00', 'time');
124 SELECT pg_input_is_valid('25:00:00', 'time');
130 SELECT pg_input_is_valid('15:36:39 America/New_York', 'time');
136 SELECT * FROM pg_input_error_info('25:00:00', 'time');
137 message | detail | hint | sql_error_code
138 ------------------------------------------------+--------+------+----------------
139 date/time field value out of range: "25:00:00" | | | 22008
142 SELECT * FROM pg_input_error_info('15:36:39 America/New_York', 'time');
143 message | detail | hint | sql_error_code
144 -----------------------------------------------------------------+--------+------+----------------
145 invalid input syntax for type time: "15:36:39 America/New_York" | | | 22007
151 -- We now make a distinction between time and intervals,
152 -- and adding two times together makes no sense at all.
153 -- Leave in one query to show that it is rejected,
154 -- and do the rest of the testing in horology.sql
155 -- where we do mixed-type arithmetic. - thomas 2000-12-02
156 SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
157 ERROR: operator is not unique: time without time zone + time without time zone
158 LINE 1: SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
160 HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
164 SELECT EXTRACT(MICROSECOND FROM TIME '2020-05-26 13:30:25.575401');
170 SELECT EXTRACT(MILLISECOND FROM TIME '2020-05-26 13:30:25.575401');
176 SELECT EXTRACT(SECOND FROM TIME '2020-05-26 13:30:25.575401');
182 SELECT EXTRACT(MINUTE FROM TIME '2020-05-26 13:30:25.575401');
188 SELECT EXTRACT(HOUR FROM TIME '2020-05-26 13:30:25.575401');
194 SELECT EXTRACT(DAY FROM TIME '2020-05-26 13:30:25.575401'); -- error
195 ERROR: unit "day" not supported for type time without time zone
196 SELECT EXTRACT(FORTNIGHT FROM TIME '2020-05-26 13:30:25.575401'); -- error
197 ERROR: unit "fortnight" not recognized for type time without time zone
198 SELECT EXTRACT(TIMEZONE FROM TIME '2020-05-26 13:30:25.575401'); -- error
199 ERROR: unit "timezone" not supported for type time without time zone
200 SELECT EXTRACT(EPOCH FROM TIME '2020-05-26 13:30:25.575401');
206 -- date_part implementation is mostly the same as extract, so only
207 -- test a few cases for additional coverage.
208 SELECT date_part('microsecond', TIME '2020-05-26 13:30:25.575401');
214 SELECT date_part('millisecond', TIME '2020-05-26 13:30:25.575401');
220 SELECT date_part('second', TIME '2020-05-26 13:30:25.575401');
226 SELECT date_part('epoch', TIME '2020-05-26 13:30:25.575401');