transactions-stable.slt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. # Verify that transaction-stable functions, like "now", don't change during a transaction.
  10. statement ok
  11. CREATE TABLE now_inc (a TIMESTAMP)
  12. statement ok
  13. INSERT INTO now_inc VALUES (now())
  14. # Sleep 2ms to ensure now() has increased, due to its ms resolution.
  15. statement ok
  16. SELECT mz_unsafe.mz_sleep(0.002)
  17. # These execute in a single txn, so should be the same, and should
  18. # produce 3 identical rows.
  19. simple
  20. BEGIN;
  21. INSERT INTO now_inc VALUES (now()), (now());
  22. INSERT INTO now_inc VALUES (now());
  23. COMMIT;
  24. ----
  25. COMPLETE 0
  26. COMPLETE 2
  27. COMPLETE 1
  28. COMPLETE 0
  29. statement ok
  30. SELECT mz_unsafe.mz_sleep(0.002)
  31. statement ok
  32. INSERT INTO now_inc VALUES (now())
  33. query I
  34. SELECT count(*) FROM now_inc GROUP BY a ORDER BY a
  35. ----
  36. 1
  37. 3
  38. 1
  39. statement ok
  40. CREATE TABLE dec (d mz_timestamp)
  41. # Verify that mz_now cannot be used in INSERTs (until
  42. # we decide what it should do in an INSERT). Previously it could, but
  43. # would produce different times even in a transaction (hence the test
  44. # in this file). Although this error message is misleading, we don't
  45. # expect users to do this, so it's ok for now.
  46. statement error db error: ERROR: calls to mz_now in write statements are not supported
  47. INSERT INTO dec VALUES (mz_now())
  48. statement ok
  49. CREATE VIEW v AS SELECT mz_now()
  50. # Check that read-then-write can look through transitive dependencies.
  51. statement error db error: ERROR: calls to mz_now in write statements are not supported
  52. INSERT INTO dec SELECT * FROM v
  53. # DELETE and UPDATE also cannot use mz_now.
  54. statement error db error: ERROR: calls to mz_now in write statements are not supported
  55. UPDATE dec SET d = mz_now()
  56. statement error db error: ERROR: calls to mz_now in write statements are not supported
  57. DELETE FROM dec WHERE d = mz_now()
  58. # RETURNING also nope.
  59. statement error db error: ERROR: calls to mz_now in write statements are not supported
  60. INSERT INTO dec VALUES (0) RETURNING mz_now()