fetch-tail-retraction.td 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #
  10. # Observe the retraction of records from a SUBSCRIBE stream
  11. #
  12. $ set-regex match=\d{13} replacement=<TIMESTAMP>
  13. > CREATE TABLE inserts (f1 INTEGER);
  14. > INSERT INTO inserts VALUES (123),(123),(NULL);
  15. > CREATE TABLE deletes (f1 INTEGER);
  16. > CREATE MATERIALIZED VIEW v1 AS SELECT * FROM inserts EXCEPT ALL SELECT * FROM deletes;
  17. > SELECT * FROM v1;
  18. 123
  19. 123
  20. <null>
  21. > BEGIN
  22. > DECLARE c CURSOR FOR SUBSCRIBE v1;
  23. > FETCH 2 c;
  24. <TIMESTAMP> 2 123
  25. <TIMESTAMP> 1 <null>
  26. #
  27. # Force a retraction by performing an update outside of the transaction and making sure
  28. # that the update has been fully ingested in v1.
  29. #
  30. # The value 999 should not cause anything to be retracted, is inserted to check
  31. # that no erroneous retractions will be issued.
  32. #
  33. $ postgres-execute connection=postgres://materialize:materialize@${testdrive.materialize-sql-addr}
  34. INSERT INTO deletes VALUES (123), (123), (NULL), (999);
  35. SELECT * FROM v1;
  36. > FETCH ALL c;
  37. <TIMESTAMP> -2 123
  38. <TIMESTAMP> -1 <null>