horology.out 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. --
  2. -- HOROLOGY
  3. --
  4. SET DateStyle = 'Postgres, MDY';
  5. -- should fail in mdy mode:
  6. SELECT timestamp with time zone '27/12/2001 04:05:06.789-08';
  7. ERROR: date/time field value out of range: "27/12/2001 04:05:06.789-08"
  8. LINE 1: SELECT timestamp with time zone '27/12/2001 04:05:06.789-08'...
  9. ^
  10. HINT: Perhaps you need a different "datestyle" setting.
  11. set datestyle to dmy;
  12. reset datestyle;
  13. SET DateStyle = 'German';
  14. SET DateStyle = 'ISO';
  15. -- As of 7.4, allow time without time zone having a time zone specified
  16. SELECT time without time zone '040506.789+08';
  17. time
  18. --------------
  19. 04:05:06.789
  20. (1 row)
  21. SELECT time without time zone '040506.789-08';
  22. time
  23. --------------
  24. 04:05:06.789
  25. (1 row)
  26. SELECT time without time zone 'T040506.789+08';
  27. time
  28. --------------
  29. 04:05:06.789
  30. (1 row)
  31. SELECT time without time zone 'T040506.789-08';
  32. time
  33. --------------
  34. 04:05:06.789
  35. (1 row)
  36. SELECT time with time zone '040506.789+08';
  37. timetz
  38. -----------------
  39. 04:05:06.789+08
  40. (1 row)
  41. SELECT time with time zone '040506.789-08';
  42. timetz
  43. -----------------
  44. 04:05:06.789-08
  45. (1 row)
  46. SELECT time with time zone 'T040506.789+08';
  47. timetz
  48. -----------------
  49. 04:05:06.789+08
  50. (1 row)
  51. SELECT time with time zone 'T040506.789-08';
  52. timetz
  53. -----------------
  54. 04:05:06.789-08
  55. (1 row)
  56. SELECT time with time zone 'T040506.789 +08';
  57. timetz
  58. -----------------
  59. 04:05:06.789+08
  60. (1 row)
  61. SELECT time with time zone 'T040506.789 -08';
  62. timetz
  63. -----------------
  64. 04:05:06.789-08
  65. (1 row)
  66. SET DateStyle = 'Postgres, MDY';
  67. -- Shorthand values
  68. -- Not directly usable for regression testing since these are not constants.
  69. -- So, just try to test parser and hope for the best - thomas 97/04/26
  70. SELECT (timestamp without time zone 'today' = (timestamp without time zone 'yesterday' + interval '1 day')) as "True";
  71. True
  72. ------
  73. t
  74. (1 row)
  75. SELECT (timestamp without time zone 'today' = (timestamp without time zone 'tomorrow' - interval '1 day')) as "True";
  76. True
  77. ------
  78. t
  79. (1 row)
  80. SELECT (timestamp without time zone 'today 10:30' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True";
  81. True
  82. ------
  83. t
  84. (1 row)
  85. SELECT (timestamp without time zone '10:30 today' = (timestamp without time zone 'yesterday' + interval '1 day 10 hr 30 min')) as "True";
  86. True
  87. ------
  88. t
  89. (1 row)
  90. SELECT (timestamp without time zone 'tomorrow' = (timestamp without time zone 'yesterday' + interval '2 days')) as "True";
  91. True
  92. ------
  93. t
  94. (1 row)
  95. SELECT (timestamp without time zone 'tomorrow 16:00:00' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True";
  96. True
  97. ------
  98. t
  99. (1 row)
  100. SELECT (timestamp without time zone '16:00:00 tomorrow' = (timestamp without time zone 'today' + interval '1 day 16 hours')) as "True";
  101. True
  102. ------
  103. t
  104. (1 row)
  105. SELECT (timestamp without time zone 'yesterday 12:34:56' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True";
  106. True
  107. ------
  108. t
  109. (1 row)
  110. SELECT (timestamp without time zone '12:34:56 yesterday' = (timestamp without time zone 'tomorrow' - interval '2 days - 12:34:56')) as "True";
  111. True
  112. ------
  113. t
  114. (1 row)
  115. SELECT (timestamp without time zone 'tomorrow' > 'now') as "True";
  116. True
  117. ------
  118. t
  119. (1 row)
  120. SELECT (timestamp with time zone 'today' = (timestamp with time zone 'yesterday' + interval '1 day')) as "True";
  121. True
  122. ------
  123. t
  124. (1 row)
  125. SELECT (timestamp with time zone 'today' = (timestamp with time zone 'tomorrow' - interval '1 day')) as "True";
  126. True
  127. ------
  128. t
  129. (1 row)
  130. SELECT (timestamp with time zone 'tomorrow' = (timestamp with time zone 'yesterday' + interval '2 days')) as "True";
  131. True
  132. ------
  133. t
  134. (1 row)
  135. SELECT (timestamp with time zone 'tomorrow' > 'now') as "True";
  136. True
  137. ------
  138. t
  139. (1 row)
  140. -- timestamp with time zone, interval arithmetic around DST change
  141. -- (just for fun, let's use an intentionally nonstandard POSIX zone spec)
  142. SET TIME ZONE 'CST7CDT,M4.1.0,M10.5.0';
  143. RESET TIME ZONE;
  144. SELECT CAST(interval '02:03' AS time) AS "02:03:00";
  145. 02:03:00
  146. ----------
  147. 02:03:00
  148. (1 row)
  149. SELECT time '01:30' + interval '02:01' AS "03:31:00";
  150. 03:31:00
  151. ----------
  152. 03:31:00
  153. (1 row)
  154. SELECT time '01:30' - interval '02:01' AS "23:29:00";
  155. 23:29:00
  156. ----------
  157. 23:29:00
  158. (1 row)
  159. SELECT time '02:30' + interval '36:01' AS "14:31:00";
  160. 14:31:00
  161. ----------
  162. 14:31:00
  163. (1 row)
  164. SELECT time '03:30' + interval '1 month 04:01' AS "07:31:00";
  165. 07:31:00
  166. ----------
  167. 07:31:00
  168. (1 row)
  169. SELECT time with time zone '01:30-08' - interval '02:01' AS "23:29:00-08";
  170. 23:29:00-08
  171. -------------
  172. 23:29:00-08
  173. (1 row)
  174. SELECT time with time zone '02:30-08' + interval '36:01' AS "14:31:00-08";
  175. 14:31:00-08
  176. -------------
  177. 14:31:00-08
  178. (1 row)
  179. -- These two tests cannot be used because they default to current timezone,
  180. -- which may be either -08 or -07 depending on the time of year.
  181. -- SELECT time with time zone '01:30' + interval '02:01' AS "03:31:00-08";
  182. -- SELECT time with time zone '03:30' + interval '1 month 04:01' AS "07:31:00-08";
  183. -- Try the following two tests instead, as a poor substitute
  184. SELECT CAST(CAST(date 'today' + time with time zone '05:30'
  185. + interval '02:01' AS time with time zone) AS time) AS "07:31:00";
  186. 07:31:00
  187. ----------
  188. 07:31:00
  189. (1 row)
  190. SELECT CAST(cast(date 'today' + time with time zone '03:30'
  191. + interval '1 month 04:01' as timestamp without time zone) AS time) AS "07:31:00";
  192. 07:31:00
  193. ----------
  194. 07:31:00
  195. (1 row)
  196. -- SQL9x OVERLAPS operator
  197. -- test with time zone
  198. SELECT (timestamp with time zone '2000-11-27', timestamp with time zone '2000-11-28')
  199. OVERLAPS (timestamp with time zone '2000-11-27 12:00', timestamp with time zone '2000-11-30') AS "True";
  200. True
  201. ------
  202. t
  203. (1 row)
  204. SELECT (timestamp with time zone '2000-11-26', timestamp with time zone '2000-11-27')
  205. OVERLAPS (timestamp with time zone '2000-11-27 12:00', timestamp with time zone '2000-11-30') AS "False";
  206. False
  207. -------
  208. f
  209. (1 row)
  210. -- test without time zone
  211. SELECT (timestamp without time zone '2000-11-27', timestamp without time zone '2000-11-28')
  212. OVERLAPS (timestamp without time zone '2000-11-27 12:00', timestamp without time zone '2000-11-30') AS "True";
  213. True
  214. ------
  215. t
  216. (1 row)
  217. SELECT (timestamp without time zone '2000-11-26', timestamp without time zone '2000-11-27')
  218. OVERLAPS (timestamp without time zone '2000-11-27 12:00', timestamp without time zone '2000-11-30') AS "False";
  219. False
  220. -------
  221. f
  222. (1 row)
  223. -- test time and interval
  224. SELECT (time '00:00', time '01:00')
  225. OVERLAPS (time '00:30', time '01:30') AS "True";
  226. True
  227. ------
  228. t
  229. (1 row)
  230. CREATE TABLE TEMP_TIMESTAMP (f1 timestamp with time zone);
  231. -- get some candidate input values
  232. INSERT INTO TEMP_TIMESTAMP (f1)
  233. SELECT d1 FROM TIMESTAMP_TBL
  234. WHERE d1 BETWEEN '13-jun-1957' AND '1-jan-1997'
  235. OR d1 BETWEEN '1-jan-1999' AND '1-jan-2010';
  236. DROP TABLE TEMP_TIMESTAMP;
  237. --
  238. -- Comparisons between datetime types, especially overflow cases
  239. ---
  240. SELECT '2202020-10-05'::date::timestamp; -- fail
  241. ERROR: date out of range for timestamp
  242. SELECT '2202020-10-05'::date > '2020-10-05'::timestamp as t;
  243. t
  244. ---
  245. t
  246. (1 row)
  247. SELECT '2020-10-05'::timestamp > '2202020-10-05'::date as f;
  248. f
  249. ---
  250. f
  251. (1 row)
  252. SELECT '2202020-10-05'::date::timestamptz; -- fail
  253. ERROR: date out of range for timestamp
  254. SELECT '2202020-10-05'::date > '2020-10-05'::timestamptz as t;
  255. t
  256. ---
  257. t
  258. (1 row)
  259. SELECT '2020-10-05'::timestamptz > '2202020-10-05'::date as f;
  260. f
  261. ---
  262. f
  263. (1 row)
  264. SET TimeZone = 'UTC-2';
  265. SELECT '4714-11-24 BC'::date < '2020-10-05'::timestamptz as t;
  266. t
  267. ---
  268. t
  269. (1 row)
  270. SELECT '2020-10-05'::timestamptz >= '4714-11-24 BC'::date as t;
  271. t
  272. ---
  273. t
  274. (1 row)
  275. SELECT '4714-11-24 BC'::timestamp < '2020-10-05'::timestamptz as t;
  276. t
  277. ---
  278. t
  279. (1 row)
  280. SELECT '2020-10-05'::timestamptz >= '4714-11-24 BC'::timestamp as t;
  281. t
  282. ---
  283. t
  284. (1 row)
  285. RESET TimeZone;
  286. --
  287. -- Formats
  288. --
  289. SET DateStyle TO 'US,Postgres';
  290. SET DateStyle TO 'US,ISO';
  291. SELECT d1 AS us_iso FROM TIMESTAMP_TBL;
  292. us_iso
  293. ------------------------
  294. -infinity
  295. infinity
  296. 1970-01-01 00:00:00
  297. 1997-02-10 17:32:01
  298. 1997-02-10 17:32:01
  299. 1997-02-10 17:32:02
  300. 1997-02-10 17:32:01.4
  301. 1997-02-10 17:32:01.5
  302. 1997-02-10 17:32:01.6
  303. 1997-01-02 00:00:00
  304. 1997-01-02 03:04:05
  305. 1997-02-10 17:32:01
  306. 1997-02-10 17:32:01
  307. 1997-02-10 17:32:01
  308. 1997-02-10 17:32:01
  309. 1997-06-10 17:32:01
  310. 2001-09-22 18:19:20
  311. 2000-03-15 08:14:01
  312. 2000-03-15 13:14:02
  313. 2000-03-15 12:14:03
  314. 2000-03-15 03:14:04
  315. 2000-03-15 02:14:05
  316. 1997-02-10 17:32:01
  317. 1997-02-10 17:32:01
  318. 1997-02-10 17:32:00
  319. 1997-02-10 17:32:01
  320. 1997-02-10 17:32:01
  321. 1997-02-10 17:32:01
  322. 1997-02-10 17:32:01
  323. 1997-02-10 17:32:01
  324. 1997-02-10 17:32:01
  325. 1997-02-10 17:32:01
  326. 1997-02-10 17:32:01
  327. 1997-02-10 17:32:01
  328. 1997-06-10 18:32:01
  329. 1997-02-10 17:32:01
  330. 1997-02-11 17:32:01
  331. 1997-02-12 17:32:01
  332. 1997-02-13 17:32:01
  333. 1997-02-14 17:32:01
  334. 1997-02-15 17:32:01
  335. 1997-02-16 17:32:01
  336. 0097-02-16 17:32:01 BC
  337. 0097-02-16 17:32:01
  338. 0597-02-16 17:32:01
  339. 1097-02-16 17:32:01
  340. 1697-02-16 17:32:01
  341. 1797-02-16 17:32:01
  342. 1897-02-16 17:32:01
  343. 1997-02-16 17:32:01
  344. 2097-02-16 17:32:01
  345. 1996-02-28 17:32:01
  346. 1996-02-29 17:32:01
  347. 1996-03-01 17:32:01
  348. 1996-12-30 17:32:01
  349. 1996-12-31 17:32:01
  350. 1997-01-01 17:32:01
  351. 1997-02-28 17:32:01
  352. 1997-03-01 17:32:01
  353. 1997-12-30 17:32:01
  354. 1997-12-31 17:32:01
  355. 1999-12-31 17:32:01
  356. 2000-01-01 17:32:01
  357. 2000-12-31 17:32:01
  358. 2001-01-01 17:32:01
  359. (65 rows)
  360. SET DateStyle TO 'US,SQL';
  361. SET DateStyle TO 'European,Postgres';
  362. SET DateStyle TO 'European,ISO';
  363. SET DateStyle TO 'European,SQL';
  364. RESET DateStyle;
  365. SELECT to_timestamp('97/Feb/16', 'YYMonDD');
  366. ERROR: invalid value "/Feb/16" for "Mon"
  367. DETAIL: The given value did not match any of the allowed values for this field.
  368. SELECT to_timestamp('2011-12-18 11:38 PST', 'YYYY-MM-DD HH12:MI TZ'); -- NYI
  369. ERROR: formatting field "TZ" is only supported in to_char
  370. SELECT to_timestamp('2000 + + JUN', 'YYYY MON');
  371. ERROR: invalid value "+" for "MON"
  372. DETAIL: The given value did not match any of the allowed values for this field.
  373. SELECT to_date('2011 x12 x18', 'YYYYxMMxDD');
  374. ERROR: invalid value "x1" for "MM"
  375. DETAIL: Value must be an integer.
  376. --
  377. -- Check errors for some incorrect usages of to_timestamp() and to_date()
  378. --
  379. -- Mixture of date conventions (ISO week and Gregorian):
  380. SELECT to_timestamp('2005527', 'YYYYIWID');
  381. ERROR: invalid combination of date conventions
  382. HINT: Do not mix Gregorian and ISO week date conventions in a formatting template.
  383. -- Insufficient characters in the source string:
  384. SELECT to_timestamp('19971', 'YYYYMMDD');
  385. ERROR: source string too short for "MM" formatting field
  386. DETAIL: Field requires 2 characters, but only 1 remain.
  387. HINT: If your source string is not fixed-width, try using the "FM" modifier.
  388. -- Insufficient digit characters for a single node:
  389. SELECT to_timestamp('19971)24', 'YYYYMMDD');
  390. ERROR: invalid value "1)" for "MM"
  391. DETAIL: Field requires 2 characters, but only 1 could be parsed.
  392. HINT: If your source string is not fixed-width, try using the "FM" modifier.
  393. -- We don't accept full-length day or month names if short form is specified:
  394. SELECT to_timestamp('Friday 1-January-1999', 'DY DD MON YYYY');
  395. ERROR: invalid value "da" for "DD"
  396. DETAIL: Value must be an integer.
  397. SELECT to_timestamp('Fri 1-January-1999', 'DY DD MON YYYY');
  398. ERROR: invalid value "uary" for "YYYY"
  399. DETAIL: Value must be an integer.
  400. -- Value clobbering:
  401. SELECT to_timestamp('1997-11-Jan-16', 'YYYY-MM-Mon-DD');
  402. ERROR: conflicting values for "Mon" field in formatting string
  403. DETAIL: This value contradicts a previous setting for the same field type.
  404. -- Non-numeric input:
  405. SELECT to_timestamp('199711xy', 'YYYYMMDD');
  406. ERROR: invalid value "xy" for "DD"
  407. DETAIL: Value must be an integer.
  408. -- Input that doesn't fit in an int:
  409. SELECT to_timestamp('10000000000', 'FMYYYY');
  410. ERROR: value for "YYYY" in source string is out of range
  411. DETAIL: Value must be in the range -2147483648 to 2147483647.
  412. -- Out-of-range and not-quite-out-of-range fields:
  413. SELECT to_timestamp('2016-06-13 25:00:00', 'YYYY-MM-DD HH24:MI:SS');
  414. ERROR: date/time field value out of range: "2016-06-13 25:00:00"
  415. SELECT to_timestamp('2016-06-13 15:60:00', 'YYYY-MM-DD HH24:MI:SS');
  416. ERROR: date/time field value out of range: "2016-06-13 15:60:00"
  417. SELECT to_timestamp('2016-06-13 15:50:60', 'YYYY-MM-DD HH24:MI:SS');
  418. ERROR: date/time field value out of range: "2016-06-13 15:50:60"
  419. SELECT to_timestamp('2016-06-13 15:50:55', 'YYYY-MM-DD HH:MI:SS');
  420. ERROR: hour "15" is invalid for the 12-hour clock
  421. HINT: Use the 24-hour clock, or give an hour between 1 and 12.
  422. SELECT to_timestamp('2016-13-01 15:50:55', 'YYYY-MM-DD HH24:MI:SS');
  423. ERROR: date/time field value out of range: "2016-13-01 15:50:55"
  424. SELECT to_timestamp('2016-02-30 15:50:55', 'YYYY-MM-DD HH24:MI:SS');
  425. ERROR: date/time field value out of range: "2016-02-30 15:50:55"
  426. SELECT to_timestamp('2015-02-29 15:50:55', 'YYYY-MM-DD HH24:MI:SS');
  427. ERROR: date/time field value out of range: "2015-02-29 15:50:55"
  428. SELECT to_timestamp('2015-02-11 86400', 'YYYY-MM-DD SSSS');
  429. ERROR: date/time field value out of range: "2015-02-11 86400"
  430. SELECT to_timestamp('2015-02-11 86400', 'YYYY-MM-DD SSSSS');
  431. ERROR: date/time field value out of range: "2015-02-11 86400"
  432. SELECT to_date('2016-13-10', 'YYYY-MM-DD');
  433. ERROR: date/time field value out of range: "2016-13-10"
  434. SELECT to_date('2016-02-30', 'YYYY-MM-DD');
  435. ERROR: date/time field value out of range: "2016-02-30"
  436. SELECT to_date('2015-02-29', 'YYYY-MM-DD');
  437. ERROR: date/time field value out of range: "2015-02-29"
  438. SELECT to_date('2015 366', 'YYYY DDD');
  439. ERROR: date/time field value out of range: "2015 366"
  440. SELECT to_date('2016 367', 'YYYY DDD');
  441. ERROR: date/time field value out of range: "2016 367"
  442. --
  443. -- Check behavior with SQL-style fixed-GMT-offset time zone (cf bug #8572)
  444. --
  445. SET TIME ZONE 'America/New_York';
  446. SET TIME ZONE '-1.5';
  447. SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD SSSS');
  448. to_char
  449. ------------------
  450. 2012-12-12 43200
  451. (1 row)
  452. SELECT to_char('2012-12-12 12:00'::timestamptz, 'YYYY-MM-DD SSSSS');
  453. to_char
  454. ------------------
  455. 2012-12-12 43200
  456. (1 row)
  457. RESET TIME ZONE;