mztimestamp.slt 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. # Test the mz_timestamp type.
  10. query TT
  11. SELECT pg_typeof(mz_now()), pg_typeof(1::mz_timestamp)
  12. ----
  13. mz_timestamp
  14. mz_timestamp
  15. query B
  16. SELECT mz_now() = mz_now()
  17. ----
  18. true
  19. query T multiline
  20. EXPLAIN OPTIMIZED PLAN WITH(humanized expressions, arity, join implementations) AS VERBOSE TEXT FOR SELECT 1::mz_timestamp = mz_now()
  21. ----
  22. Explained Query:
  23. Map ((1 = mz_now())) // { arity: 1 }
  24. Constant // { arity: 0 }
  25. - ()
  26. Target cluster: quickstart
  27. EOF
  28. query B
  29. SELECT 0::mz_timestamp <= mz_now()
  30. ----
  31. true
  32. statement ok
  33. CREATE VIEW intervals (a, b) AS VALUES (1, 10), (1, 2), (2, 13), (3, 1), (-3, 10), (5, 18446744073709551616)
  34. statement ok
  35. CREATE MATERIALIZED VIEW valid AS
  36. SELECT *
  37. FROM intervals
  38. WHERE mz_now() BETWEEN a AND b;
  39. query TTBBBB
  40. SELECT
  41. '1702129950259'::mz_timestamp::text,
  42. '1990-01-04 11:00'::mz_timestamp::text,
  43. greatest('1990-01-04 11:00', mz_now()) > '1990-01-04 11:00'::mz_timestamp,
  44. least('1990-01-04 11:00', mz_now()) > '1990-01-04 11:00'::mz_timestamp,
  45. greatest(mz_now(), '1990-01-04 11:00') > '3000-01-04 11:00'::mz_timestamp,
  46. '1990-01-04 11:00+08'::mz_timestamp < '1990-01-04 11:00+06'::mz_timestamp;
  47. ----
  48. 1702129950259
  49. 631450800000
  50. true
  51. false
  52. false
  53. true
  54. # Bad timestamp string
  55. query error invalid input syntax for type mz_timestamp: could not parse mz_timestamp: could not parse as number of milliseconds since epoch; could not parse as date and time: invalid input syntax for type timestamp with time zone: YEAR, MONTH, DAY are all required: "1990\-01": "1990\-01"
  56. SELECT '1990-01'::mz_timestamp;
  57. # This would be negative milliseconds since the Unix epoch
  58. query error invalid input syntax for type mz_timestamp: could not parse mz_timestamp: out of range for mz_timestamp: "1960\-01\-01 11:00"
  59. SELECT '1960-01-01 11:00'::mz_timestamp;
  60. query T
  61. SELECT 1::mz_catalog.mz_timestamp
  62. ----
  63. 1
  64. query T
  65. SELECT '1970-01-02'::date::mz_timestamp
  66. ----
  67. 86400000
  68. # Casts to timestamp[tz]. 8210266815600000 is roughly `HIGH_DATE` for `CheckedTimestamp`.
  69. query T
  70. SELECT 8210266815600000::mz_timestamp::timestamptz
  71. ----
  72. 262142-12-31 07:00:00+00
  73. # Roughly `HIGH_DATE` + 1 day.
  74. query error timestamp out of range
  75. SELECT 8210266898400000::mz_timestamp::timestamp
  76. query error timestamp out of range
  77. SELECT 18446744073709551615::mz_timestamp::timestamp
  78. query error timestamp out of range
  79. SELECT 8210266898400000::mz_timestamp::timestamptz