types-double.td 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 the floating-point types
  11. #
  12. > CREATE SECRET pgpass AS 'postgres'
  13. > CREATE CONNECTION pg TO POSTGRES (
  14. HOST postgres,
  15. DATABASE postgres,
  16. USER postgres,
  17. PASSWORD SECRET pgpass
  18. )
  19. # Insert data pre-snapshot
  20. $ postgres-execute connection=postgres://postgres:postgres@postgres
  21. ALTER USER postgres WITH replication;
  22. DROP SCHEMA IF EXISTS public CASCADE;
  23. DROP PUBLICATION IF EXISTS mz_source;
  24. CREATE SCHEMA public;
  25. CREATE TABLE t1 (f1 REAL, f2 DOUBLE PRECISION);
  26. ALTER TABLE t1 REPLICA IDENTITY FULL;
  27. INSERT INTO t1 VALUES (NULL, NULL);
  28. INSERT INTO t1 VALUES ('-Inf', '-Inf')
  29. INSERT INTO t1 VALUES ('NaN', 'NaN');
  30. INSERT INTO t1 VALUES ('+Inf', '+Inf');
  31. INSERT INTO t1 VALUES ('0.000000000000000000000000000001', '0.000000000000000000000000000001');
  32. INSERT INTO t1 VALUES ('-1111111111111111111111111111111', '-1111111111111111111111111111111');
  33. CREATE PUBLICATION mz_source FOR ALL TABLES;
  34. > CREATE SOURCE mz_source FROM POSTGRES CONNECTION pg (PUBLICATION 'mz_source');
  35. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE t1);
  36. > SELECT COUNT(*) > 0 FROM t1;
  37. true
  38. # Insert the same data post-snapshot
  39. $ postgres-execute connection=postgres://postgres:postgres@postgres
  40. INSERT INTO t1 SELECT * FROM t1;
  41. > SELECT pg_typeof(f1), pg_typeof(f2) FROM t1 LIMIT 1;
  42. "real" "double precision"
  43. # Note that there is some expected loss of precision on the very large numbers
  44. > SELECT * FROM t1;
  45. -1111111100000000000000000000000 -1111111111111111000000000000000
  46. -1111111100000000000000000000000 -1111111111111111000000000000000
  47. -inf -inf
  48. -inf -inf
  49. 0.000000000000000000000000000001 0.000000000000000000000000000001
  50. 0.000000000000000000000000000001 0.000000000000000000000000000001
  51. <null> <null>
  52. <null> <null>
  53. NaN NaN
  54. NaN NaN
  55. inf inf
  56. inf inf