as_of.slt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/as_of
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. # not supported yet
  20. halt
  21. mode cockroach
  22. # Unlikely to support the SELECT ... AS OF SYSTEM TIME syntax exactly.
  23. halt
  24. statement ok
  25. CREATE TABLE t (i INT)
  26. statement ok
  27. INSERT INTO t VALUES (2)
  28. # Verify strings can be parsed as intervals.
  29. query I
  30. SELECT * FROM t AS OF SYSTEM TIME '-1us'
  31. ----
  32. 2
  33. # Verify a forced interval type works.
  34. query I
  35. SELECT * FROM t AS OF SYSTEM TIME INTERVAL '-1us'
  36. ----
  37. 2
  38. # Verify that we can use computed expressions.
  39. query I
  40. SELECT * FROM t AS OF SYSTEM TIME -( ('1000' || 'us')::INTERVAL )
  41. ----
  42. 2
  43. statement error pq: AS OF SYSTEM TIME: only constant expressions or experimental_follower_read_timestamp are allowed
  44. SELECT * FROM t AS OF SYSTEM TIME cluster_logical_timestamp()
  45. statement error pq: subqueries are not allowed in AS OF SYSTEM TIME
  46. SELECT * FROM t AS OF SYSTEM TIME (SELECT '-1h'::INTERVAL)
  47. statement error pq: relation "t" does not exist
  48. SELECT * FROM t AS OF SYSTEM TIME '-1h'
  49. statement error pq: experimental_follower_read_timestamp\(\): experimental_follower_read_timestamp is only available in ccl distribution
  50. SELECT * FROM t AS OF SYSTEM TIME experimental_follower_read_timestamp()
  51. statement error pq: unknown signature: experimental_follower_read_timestamp\(string\) \(desired <timestamptz>\)
  52. SELECT * FROM t AS OF SYSTEM TIME experimental_follower_read_timestamp('boom')
  53. statement error pq: AS OF SYSTEM TIME: only constant expressions or experimental_follower_read_timestamp are allowed
  54. SELECT * FROM t AS OF SYSTEM TIME now()
  55. statement error cannot specify timestamp in the future
  56. SELECT * FROM t AS OF SYSTEM TIME '10s'
  57. # Verify that the TxnTimestamp used to generate now() and current_timestamp() is
  58. # set to the historical timestamp.
  59. query T
  60. SELECT * FROM (SELECT now()) AS OF SYSTEM TIME '2018-01-01'
  61. ----
  62. 2018-01-01 00:00:00 +0000 UTC
  63. # Verify that zero intervals indistinguishable from zero cause an error.
  64. statement error pq: AS OF SYSTEM TIME: interval value '0.1us' too small, must be <= -1µs
  65. SELECT * FROM t AS OF SYSTEM TIME '0.1us'
  66. statement error pq: AS OF SYSTEM TIME: interval value '0,0' too small, must be <= -1µs
  67. SELECT * FROM t AS OF SYSTEM TIME '0,0'
  68. statement error pq: AS OF SYSTEM TIME: interval value '0.000000000,0' too small, must be <= -1µs
  69. SELECT * FROM t AS OF SYSTEM TIME '0.000000000,0'
  70. statement error pq: AS OF SYSTEM TIME: interval value '-0.1us' too small, must be <= -1µs
  71. SELECT * FROM t AS OF SYSTEM TIME '-0.1us'
  72. statement error pq: AS OF SYSTEM TIME: zero timestamp is invalid
  73. SELECT * FROM t AS OF SYSTEM TIME '0'