fetch-tail-query.td 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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 that non-views can be used in SUBSCRIBE.
  10. $ set-regex match=\d{13,20} replacement=<TIMESTAMP>
  11. > CREATE TABLE t1 (f1 INTEGER);
  12. > INSERT INTO t1 VALUES (123);
  13. > BEGIN
  14. > DECLARE c CURSOR FOR SUBSCRIBE (SELECT * FROM t1)
  15. > FETCH ALL c
  16. <TIMESTAMP> 1 123
  17. > COMMIT
  18. > SUBSCRIBE (WITH a(x) AS (SELECT 'a') SELECT generate_series(1, 2), x FROM a)
  19. <TIMESTAMP> 1 1 a
  20. <TIMESTAMP> 1 2 a
  21. > CREATE MATERIALIZED VIEW v1 AS SELECT count(*) FROM t1
  22. > CREATE VIEW v2 AS SELECT 3
  23. > BEGIN
  24. > DECLARE c CURSOR FOR SUBSCRIBE (SELECT * FROM v1, v2)
  25. > FETCH ALL c
  26. <TIMESTAMP> 1 1 3
  27. > COMMIT
  28. # Verify SUBSCRIBE behavior when the query includes an ORDER BY and a LIMIT.
  29. # Check that the initial output of the SUBSCRIBE is correct.
  30. > BEGIN
  31. > DECLARE c CURSOR FOR SUBSCRIBE (SELECT * FROM t1 ORDER BY 1 DESC LIMIT 1)
  32. > FETCH ALL c
  33. <TIMESTAMP> 1 123
  34. # Insert a value from another connection that is not a new maximum.
  35. $ postgres-connect name=alt url=postgres://materialize:materialize@${testdrive.materialize-sql-addr}
  36. $ postgres-execute connection=alt
  37. INSERT INTO t1 VALUES (100)
  38. # Verify that the SUBSCRIBE does not emit any updates.
  39. > FETCH ALL c WITH (timeout = '100ms')
  40. # Insert a value from another connection that *is* a new maximum.
  41. $ postgres-execute connection=alt
  42. INSERT INTO t1 VALUES (124)
  43. # Verify that the SUBSCRIBE emits the new maximum.
  44. > FETCH ALL c
  45. <TIMESTAMP> -1 123
  46. <TIMESTAMP> 1 124