decimal-distinct.td 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 that decimal numbers that are the same are considered identical
  11. # and those that are truly different are considered distinct
  12. #
  13. #
  14. # Truly distinct numbers
  15. #
  16. > CREATE TABLE decimal_distinct (f1 DECIMAL);
  17. > INSERT INTO decimal_distinct VALUES ('-999999999999999999999999999999999999999');
  18. > INSERT INTO decimal_distinct VALUES ('-1.00000000000000000000000000000000000001');
  19. > INSERT INTO decimal_distinct VALUES ('-0.999999999999999999999999999999999999999');
  20. > INSERT INTO decimal_distinct VALUES ('-0.000000000000000000000000000000000000001');
  21. > INSERT INTO decimal_distinct VALUES ('0.000000000000000000000000000000000000001');
  22. > INSERT INTO decimal_distinct VALUES ('0.000000000000000000000000000000000000002');
  23. > INSERT INTO decimal_distinct VALUES ('0.999999999999999999999999999999999999998');
  24. > INSERT INTO decimal_distinct VALUES ('0.999999999999999999999999999999999999999');
  25. > INSERT INTO decimal_distinct VALUES ('1.00000000000000000000000000000000000001');
  26. > INSERT INTO decimal_distinct VALUES ('1.00000000000000000000000000000000000002');
  27. > INSERT INTO decimal_distinct VALUES ('999999999999999999999999999999999999999');
  28. > INSERT INTO decimal_distinct VALUES ('999999999999999999999999999999999999998');
  29. > SELECT DISTINCT f1 FROM decimal_distinct;
  30. -999999999999999999999999999999999999999
  31. -1.00000000000000000000000000000000000001
  32. -0.999999999999999999999999999999999999999
  33. -0.000000000000000000000000000000000000001
  34. 0.000000000000000000000000000000000000001
  35. 0.000000000000000000000000000000000000002
  36. 0.999999999999999999999999999999999999998
  37. 0.999999999999999999999999999999999999999
  38. 1.00000000000000000000000000000000000001
  39. 1.00000000000000000000000000000000000002
  40. 999999999999999999999999999999999999998
  41. 999999999999999999999999999999999999999
  42. > SELECT f1 FROM decimal_distinct UNION DISTINCT SELECT * FROM decimal_distinct;
  43. -999999999999999999999999999999999999999
  44. -1.00000000000000000000000000000000000001
  45. -0.999999999999999999999999999999999999999
  46. -0.000000000000000000000000000000000000001
  47. 0.000000000000000000000000000000000000001
  48. 0.000000000000000000000000000000000000002
  49. 0.999999999999999999999999999999999999998
  50. 0.999999999999999999999999999999999999999
  51. 1.00000000000000000000000000000000000001
  52. 1.00000000000000000000000000000000000002
  53. 999999999999999999999999999999999999998
  54. 999999999999999999999999999999999999999
  55. > SELECT COUNT(DISTINCT f1), COUNT(*) FROM decimal_distinct;
  56. 12 12
  57. > SELECT COUNT(DISTINCT f1::DECIMAL(5,2)) FROM decimal_distinct WHERE f1 BETWEEN -1 AND 1;
  58. 3
  59. #
  60. # Fundamentally "identical" numbers as far as the DECIMAL type is concerned
  61. #
  62. > CREATE TABLE decimal_same (f1 DECIMAL);
  63. > INSERT INTO decimal_same VALUES (0),(-0);
  64. # The numbers below differ only in the part that is outside of the precision of the DECIMAL type
  65. > INSERT INTO decimal_same VALUES ('999999999999999999999999999999999999999.1');
  66. > INSERT INTO decimal_same VALUES ('999999999999999999999999999999999999999.2');
  67. # The number of leading or trailing zeroes should not matter
  68. > INSERT INTO decimal_same VALUES ('1.010');
  69. > INSERT INTO decimal_same VALUES ('1.01000');
  70. > INSERT INTO decimal_same VALUES ('001.01');
  71. > SELECT DISTINCT f1 FROM decimal_same;
  72. 0
  73. 1.01
  74. 999999999999999999999999999999999999999
  75. > SELECT COUNT(DISTINCT f1) FROM decimal_same;
  76. 3
  77. > SELECT f1 FROM decimal_same GROUP BY 1;
  78. 0
  79. 1.01
  80. 999999999999999999999999999999999999999