ct_upsert.slt 886 B

123456789101112131415161718192021222324252627282930313233343536
  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. mode cockroach
  10. statement ok
  11. CREATE TABLE append_only (key INT, val INT)
  12. statement ok
  13. CREATE CONTINUAL TASK upsert (key INT, val INT) ON INPUT append_only AS (
  14. DELETE FROM upsert WHERE key IN (SELECT key FROM append_only);
  15. INSERT INTO upsert SELECT key, max(val) FROM append_only GROUP BY key;
  16. )
  17. statement ok
  18. INSERT INTO append_only VALUES (1, 2), (1, 1)
  19. query II
  20. SELECT * FROM upsert
  21. ----
  22. 1 2
  23. statement ok
  24. INSERT INTO append_only VALUES (1, 3), (2, 4)
  25. query IT
  26. SELECT * FROM upsert
  27. ----
  28. 1 3
  29. 2 4