62-concurrent-update-nopk.td 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Concurrent update on the same table.
  11. #
  12. $ postgres-execute connection=postgres://postgres:postgres@postgres
  13. CREATE TABLE concurrent_update (f1 INTEGER, f2 TEXT, f3 INTEGER PRIMARY KEY);
  14. ALTER TABLE concurrent_update REPLICA IDENTITY FULL;
  15. INSERT INTO concurrent_update VALUES (1, 'r1', 0);
  16. INSERT INTO concurrent_update VALUES (11, 'r2', 1);
  17. $ schema-registry-wait topic=postgres.public.concurrent_update
  18. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  19. URL '${testdrive.schema-registry-url}'
  20. );
  21. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  22. > CREATE SOURCE concurrent_update
  23. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.concurrent_update');
  24. > CREATE TABLE concurrent_update_tbl FROM SOURCE concurrent_update (REFERENCE "postgres.public.concurrent_update")
  25. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  26. ENVELOPE DEBEZIUM;
  27. $ postgres-connect name=conn1 url=postgres://postgres:postgres@postgres
  28. $ postgres-connect name=conn2 url=postgres://postgres:postgres@postgres
  29. $ postgres-execute connection=conn1
  30. BEGIN;
  31. UPDATE concurrent_update SET f1 = f1 + 20 WHERE f1 = 1;
  32. $ postgres-execute connection=conn2
  33. BEGIN;
  34. UPDATE concurrent_update SET f1 = f1 + 20 WHERE f1 = 11;
  35. $ postgres-execute connection=conn1
  36. UPDATE concurrent_update SET f1 = f1 * 2 WHERE f1 = 21;
  37. COMMIT;
  38. $ postgres-execute connection=conn2
  39. UPDATE concurrent_update SET f1 = f1 * 10 WHERE f1 = 31;
  40. COMMIT;
  41. > SELECT f1, f2 FROM concurrent_update_tbl;
  42. 42 r1
  43. 310 r2