types-double.td 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. $ set-sql-timeout duration=1s
  10. #
  11. # Test the floating-point types
  12. #
  13. > CREATE SECRET mysqlpass AS '${arg.mysql-root-password}'
  14. > CREATE CONNECTION mysql_conn TO MYSQL (
  15. HOST mysql,
  16. USER root,
  17. PASSWORD SECRET mysqlpass
  18. )
  19. $ mysql-connect name=mysql url=mysql://root@mysql password=${arg.mysql-root-password}
  20. $ mysql-execute name=mysql
  21. DROP DATABASE IF EXISTS public;
  22. CREATE DATABASE public;
  23. USE public;
  24. # disable strict mode
  25. SET SESSION sql_mode=''
  26. CREATE TABLE t1 (f1 FLOAT, f2 DOUBLE);
  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 ('-11111111', '-11111111');
  33. INSERT INTO t1 VALUES ('-111111111', '-111111111');
  34. INSERT INTO t1 VALUES ('-11111111111', '-11111111111');
  35. INSERT INTO t1 VALUES ('-1111111111111', '-1111111111111');
  36. INSERT INTO t1 VALUES ('-111111111111111', '-111111111111111');
  37. INSERT INTO t1 VALUES ('-11111111111111111', '-11111111111111111');
  38. INSERT INTO t1 VALUES ('-1111111111111111111', '-1111111111111111111');
  39. INSERT INTO t1 VALUES ('-111111111111111111111', '-111111111111111111111');
  40. INSERT INTO t1 VALUES ('-1111111111111111111111111', '-1111111111111111111111111');
  41. INSERT INTO t1 VALUES ('-11111111111111111111111111111', '-11111111111111111111111111111');
  42. INSERT INTO t1 VALUES ('-1111111111111111111111111111111', '-1111111111111111111111111111111');
  43. # REAL in pg maps to DOUBLE in MySQL
  44. CREATE TABLE t2 (f1 REAL);
  45. INSERT INTO t2 VALUES ('-Inf');
  46. INSERT INTO t2 VALUES ('-0.1111111111');
  47. > CREATE SOURCE mz_source FROM MYSQL CONNECTION mysql_conn;
  48. > CREATE TABLE t1 FROM SOURCE mz_source (REFERENCE public.t1);
  49. > CREATE TABLE t2 FROM SOURCE mz_source (REFERENCE public.t2);
  50. > SELECT COUNT(*) > 0 FROM t1;
  51. true
  52. # Insert the same data post-snapshot
  53. $ mysql-execute name=mysql
  54. INSERT INTO t1 SELECT * FROM t1;
  55. > SELECT pg_typeof(f1), pg_typeof(f2) FROM t1 LIMIT 1;
  56. "real" "double precision"
  57. > SELECT pg_typeof(f1) FROM t2 LIMIT 1;
  58. "double precision"
  59. # Note that there is some expected loss of precision on the very large numbers
  60. > SELECT * FROM t1;
  61. -1111111100000000000000000000000 -1111111111111111000000000000000
  62. -1111111100000000000000000000000 -1111111111111111000000000000000
  63. -11111111000000000000000000000 -11111111111111112000000000000
  64. -11111111000000000000000000000 -11111111111111112000000000000
  65. -11111111 -11111111
  66. -11111111 -11111111
  67. -111111110 -111111111
  68. -111111110 -111111111
  69. -11111111000 -11111111111
  70. -11111111000 -11111111111
  71. -1111111100000 -1111111111111
  72. -1111111100000 -1111111111111
  73. -1111111100000000000 -1111111111111111200
  74. -1111111100000000000 -1111111111111111200
  75. -111111110000000000000 -111111111111111110000
  76. -111111110000000000000 -111111111111111110000
  77. -1111111100000000000000000 -1111111111111111100000000
  78. -1111111100000000000000000 -1111111111111111100000000
  79. -111111114000000 -111111111111111
  80. -111111114000000 -111111111111111
  81. -11111112000000000 -11111111111111112
  82. -11111112000000000 -11111111111111112
  83. 0 0
  84. 0 0
  85. 0 0
  86. 0 0
  87. 0 0
  88. 0 0
  89. 0.000000000000000000000000000001 0.000000000000000000000000000001
  90. 0.000000000000000000000000000001 0.000000000000000000000000000001
  91. <null> <null>
  92. <null> <null>
  93. > SELECT * FROM t2;
  94. -0.1111111111
  95. 0
  96. # reset MySQL config
  97. $ mysql-execute name=mysql
  98. SET SESSION sql_mode=default