11-change-date-timestamp.td 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. # Change a column from DATE to TIMESTAMP is not allowed
  11. #
  12. $ postgres-execute connection=postgres://postgres:postgres@postgres
  13. CREATE TABLE alter_change_date_timestamp (f1 DATE, f2 INTEGER PRIMARY KEY);
  14. ALTER TABLE alter_change_date_timestamp REPLICA IDENTITY FULL;
  15. INSERT INTO alter_change_date_timestamp VALUES ('2011-11-11', 0),('2012-12-12', 1);
  16. $ schema-registry-wait topic=postgres.public.alter_change_date_timestamp
  17. > CREATE CONNECTION IF NOT EXISTS csr_conn TO CONFLUENT SCHEMA REGISTRY (
  18. URL '${testdrive.schema-registry-url}'
  19. );
  20. > CREATE CONNECTION IF NOT EXISTS kafka_conn TO KAFKA (BROKER '${testdrive.kafka-addr}', SECURITY PROTOCOL PLAINTEXT);
  21. > CREATE SOURCE alter_change_date_timestamp
  22. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.alter_change_date_timestamp');
  23. > CREATE TABLE alter_change_date_timestamp_tbl FROM SOURCE alter_change_date_timestamp (REFERENCE "postgres.public.alter_change_date_timestamp")
  24. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  25. ENVELOPE DEBEZIUM;
  26. > SELECT f1 FROM alter_change_date_timestamp_tbl;
  27. 2011-11-11
  28. 2012-12-12
  29. $ postgres-execute connection=postgres://postgres:postgres@postgres
  30. ALTER TABLE alter_change_date_timestamp ALTER COLUMN f1 TYPE TIMESTAMP;
  31. INSERT INTO alter_change_date_timestamp VALUES ('2011-11-11 11:11:11', 2);
  32. UPDATE alter_change_date_timestamp SET f1 = '2012-12-12 12:12:12' WHERE f1 = '2012-12-12';
  33. DELETE FROM alter_change_date_timestamp WHERE f1 = '2011-11-11';
  34. ! SELECT * FROM alter_change_date_timestamp_tbl;
  35. contains:Failed to match writer union variant `TimestampMicro` against any variant in the reader for field `postgres.public.alter_change_date_timestamp.Value.f1`