23-types-decimal.td 1.6 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. # Make sure that the decimal type is replicated correctly
  11. #
  12. $ postgres-execute connection=postgres://postgres:postgres@postgres
  13. CREATE TABLE decimal_type (f1 DECIMAL(5,3), f2 INTEGER PRIMARY KEY);
  14. ALTER TABLE decimal_type REPLICA IDENTITY FULL;
  15. INSERT INTO decimal_type VALUES (NULL, 0), (NULL, 1), (12.345, 2), ('NaN', 3);
  16. $ schema-registry-wait topic=postgres.public.decimal_type
  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 decimal_type
  22. FROM KAFKA CONNECTION kafka_conn (TOPIC 'postgres.public.decimal_type');
  23. > CREATE TABLE decimal_type_tbl FROM SOURCE decimal_type (REFERENCE "postgres.public.decimal_type")
  24. FORMAT AVRO USING CONFLUENT SCHEMA REGISTRY CONNECTION csr_conn
  25. ENVELOPE DEBEZIUM;
  26. # NaN arrives as NULL
  27. > SELECT f1 FROM decimal_type_tbl;
  28. 12.345
  29. <null>
  30. <null>
  31. <null>
  32. $ postgres-execute connection=postgres://postgres:postgres@postgres
  33. UPDATE decimal_type SET f1 = NULL WHERE f1 = 'NaN';
  34. UPDATE decimal_type SET f1 = 0.123 WHERE f1 = 12.345;
  35. UPDATE decimal_type SET f1 = 'NaN' WHERE f1 IS NULL;
  36. > SELECT f1 FROM decimal_type_tbl;
  37. <null>
  38. <null>
  39. <null>
  40. 0.123