12-change-decimal.td 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. # Changing the definition of a DECIMAL column results in a source error
  11. # see discussion in https://github.com/MaterializeInc/database-issues/issues/2032
  12. #
  13. $ postgres-execute connection=postgres://postgres:postgres@postgres
  14. CREATE TABLE alter_change_decimal (f1 DECIMAL(5,3), f2 INTEGER PRIMARY KEY);
  15. ALTER TABLE alter_change_decimal REPLICA IDENTITY FULL;
  16. INSERT INTO alter_change_decimal VALUES (0, 0),(NULL, 1),(12.345, 2);
  17. $ schema-registry-wait topic=postgres.public.alter_change_decimal
  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 alter_change_decimal
  23. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.alter_change_decimal');
  24. > CREATE TABLE alter_change_decimal_tbl FROM SOURCE alter_change_decimal (REFERENCE "postgres.public.alter_change_decimal")
  25. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  26. ENVELOPE DEBEZIUM;
  27. > SELECT f1 FROM alter_change_decimal_tbl;
  28. <null>
  29. 0
  30. 12.345
  31. $ postgres-execute connection=postgres://postgres:postgres@postgres
  32. ALTER TABLE alter_change_decimal ALTER COLUMN f1 TYPE DECIMAL(6,4);
  33. INSERT INTO alter_change_decimal VALUES (23.456, 3);
  34. UPDATE alter_change_decimal SET f1 = 34.567 WHERE f1 = 0;
  35. ! SELECT * FROM alter_change_decimal_tbl;
  36. contains:Decimal types must match in precision, scale, and fixed size