06-add-column-with-update.td 1.9 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. # Test that adding a column does not mess things up.
  11. # We expect that updates where the data is only different in this column will
  12. # be handled correctly.
  13. #
  14. $ postgres-execute connection=postgres://postgres:postgres@postgres
  15. CREATE TABLE alter_add_column (f1 INTEGER PRIMARY KEY);
  16. ALTER TABLE alter_add_column REPLICA IDENTITY FULL;
  17. INSERT INTO alter_add_column VALUES (123);
  18. $ schema-registry-wait topic=postgres.public.alter_add_column
  19. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  20. URL '${testdrive.schema-registry-url}'
  21. );
  22. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  23. > CREATE SOURCE alter_add_column
  24. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.alter_add_column');
  25. > CREATE TABLE alter_add_column_tbl FROM SOURCE alter_add_column (REFERENCE "postgres.public.alter_add_column")
  26. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  27. ENVELOPE DEBEZIUM;
  28. > SELECT * FROM alter_add_column_tbl;
  29. 123
  30. $ postgres-execute connection=postgres://postgres:postgres@postgres
  31. ALTER TABLE alter_add_column ADD COLUMN new_column INTEGER DEFAULT 1;
  32. INSERT INTO alter_add_column VALUES (1234,2);
  33. UPDATE alter_add_column SET f1 = f1 * 10 WHERE new_column = 1;
  34. UPDATE alter_add_column SET f1 = f1 * 100 WHERE new_column = 2;
  35. # Even though we do not have new_column in our source, we expect that the
  36. # updates above have landed on the appropriate distinct rows
  37. > SELECT * FROM alter_add_column_tbl;
  38. 1230
  39. 123400