time.out 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. --
  2. -- TIME
  3. --
  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');
  20. ^
  21. SELECT f1 AS "Time" FROM TIME_TBL;
  22. Time
  23. -------------
  24. 00:00:00
  25. 01:00:00
  26. 02:03:00
  27. 11:59:00
  28. 12:00:00
  29. 12:01:00
  30. 23:59:00
  31. 23:59:59.99
  32. 15:36:39
  33. 15:36:39
  34. (10 rows)
  35. SELECT f1 AS "Three" FROM TIME_TBL WHERE f1 < '05:06:07';
  36. Three
  37. ----------
  38. 00:00:00
  39. 01:00:00
  40. 02:03:00
  41. (3 rows)
  42. SELECT f1 AS "Five" FROM TIME_TBL WHERE f1 > '05:06:07';
  43. Five
  44. -------------
  45. 11:59:00
  46. 12:00:00
  47. 12:01:00
  48. 23:59:00
  49. 23:59:59.99
  50. 15:36:39
  51. 15:36:39
  52. (7 rows)
  53. SELECT f1 AS "None" FROM TIME_TBL WHERE f1 < '00:00';
  54. None
  55. ------
  56. (0 rows)
  57. SELECT f1 AS "Eight" FROM TIME_TBL WHERE f1 >= '00:00';
  58. Eight
  59. -------------
  60. 00:00:00
  61. 01:00:00
  62. 02:03:00
  63. 11:59:00
  64. 12:00:00
  65. 12:01:00
  66. 23:59:00
  67. 23:59:59.99
  68. 15:36:39
  69. 15:36:39
  70. (10 rows)
  71. -- Check edge cases
  72. SELECT '23:59:59.999999'::time;
  73. time
  74. -----------------
  75. 23:59:59.999999
  76. (1 row)
  77. SELECT '23:59:59.9999999'::time; -- rounds up
  78. time
  79. ----------
  80. 24:00:00
  81. (1 row)
  82. SELECT '23:59:60'::time; -- rounds up
  83. time
  84. ----------
  85. 24:00:00
  86. (1 row)
  87. SELECT '24:00:00'::time; -- allowed
  88. time
  89. ----------
  90. 24:00:00
  91. (1 row)
  92. SELECT '24:00:00.01'::time; -- not allowed
  93. ERROR: date/time field value out of range: "24:00:00.01"
  94. LINE 1: SELECT '24:00:00.01'::time;
  95. ^
  96. SELECT '23:59:60.01'::time; -- not allowed
  97. ERROR: date/time field value out of range: "23:59:60.01"
  98. LINE 1: SELECT '23:59:60.01'::time;
  99. ^
  100. SELECT '24:01:00'::time; -- not allowed
  101. ERROR: date/time field value out of range: "24:01:00"
  102. LINE 1: SELECT '24:01:00'::time;
  103. ^
  104. SELECT '25:00:00'::time; -- not allowed
  105. ERROR: date/time field value out of range: "25:00:00"
  106. LINE 1: SELECT '25:00:00'::time;
  107. ^
  108. --
  109. -- TIME simple math
  110. --
  111. -- We now make a distinction between time and intervals,
  112. -- and adding two times together makes no sense at all.
  113. -- Leave in one query to show that it is rejected,
  114. -- and do the rest of the testing in horology.sql
  115. -- where we do mixed-type arithmetic. - thomas 2000-12-02
  116. SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
  117. ERROR: operator is not unique: time without time zone + time without time zone
  118. LINE 1: SELECT f1 + time '00:01' AS "Illegal" FROM TIME_TBL;
  119. ^
  120. HINT: Could not choose a best candidate operator. You might need to add explicit type casts.
  121. --
  122. -- test EXTRACT
  123. --
  124. SELECT EXTRACT(MICROSECOND FROM TIME '2020-05-26 13:30:25.575401');
  125. extract
  126. ----------
  127. 25575401
  128. (1 row)
  129. SELECT EXTRACT(MILLISECOND FROM TIME '2020-05-26 13:30:25.575401');
  130. extract
  131. -----------
  132. 25575.401
  133. (1 row)
  134. SELECT EXTRACT(SECOND FROM TIME '2020-05-26 13:30:25.575401');
  135. extract
  136. -----------
  137. 25.575401
  138. (1 row)
  139. SELECT EXTRACT(MINUTE FROM TIME '2020-05-26 13:30:25.575401');
  140. extract
  141. ---------
  142. 30
  143. (1 row)
  144. SELECT EXTRACT(HOUR FROM TIME '2020-05-26 13:30:25.575401');
  145. extract
  146. ---------
  147. 13
  148. (1 row)
  149. SELECT EXTRACT(DAY FROM TIME '2020-05-26 13:30:25.575401'); -- error
  150. ERROR: "time" units "day" not recognized
  151. SELECT EXTRACT(FORTNIGHT FROM TIME '2020-05-26 13:30:25.575401'); -- error
  152. ERROR: "time" units "fortnight" not recognized
  153. SELECT EXTRACT(TIMEZONE FROM TIME '2020-05-26 13:30:25.575401'); -- error
  154. ERROR: "time" units "timezone" not recognized
  155. SELECT EXTRACT(EPOCH FROM TIME '2020-05-26 13:30:25.575401');
  156. extract
  157. --------------
  158. 48625.575401
  159. (1 row)
  160. -- date_part implementation is mostly the same as extract, so only
  161. -- test a few cases for additional coverage.
  162. SELECT date_part('microsecond', TIME '2020-05-26 13:30:25.575401');
  163. date_part
  164. -----------
  165. 25575401
  166. (1 row)
  167. SELECT date_part('millisecond', TIME '2020-05-26 13:30:25.575401');
  168. date_part
  169. -----------
  170. 25575.401
  171. (1 row)
  172. SELECT date_part('second', TIME '2020-05-26 13:30:25.575401');
  173. date_part
  174. -----------
  175. 25.575401
  176. (1 row)
  177. SELECT date_part('epoch', TIME '2020-05-26 13:30:25.575401');
  178. date_part
  179. --------------
  180. 48625.575401
  181. (1 row)