github-5797.slt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. mode cockroach
  10. # The following is a regression test for cases 3), 4), and 6)
  11. # of https://github.com/MaterializeInc/database-issues/issues/5797,
  12. # where aggregate functions would type-promote to floating point,
  13. # but could promote to numeric.
  14. statement ok
  15. CREATE TABLE t_19511_case_3 (row_index INT, decimal_39_8_val DECIMAL(39,8));
  16. statement ok
  17. INSERT INTO t_19511_case_3 VALUES (3, 9999999999999999999999999999999.99999999::DECIMAL(39,8));
  18. statement ok
  19. INSERT INTO t_19511_case_3 VALUES (4, -9999999999999999999999999999999.99999999::DECIMAL(39,8));
  20. statement ok
  21. CREATE OR REPLACE VIEW v_19511_case_3 (row_index, decimal_39_8_val)
  22. AS SELECT 3, 9999999999999999999999999999999.99999999::DECIMAL(39,8)
  23. UNION SELECT 4, -9999999999999999999999999999999.99999999::DECIMAL(39,8);
  24. # Note that we get an error in the evaluation of this case, while
  25. # PostgreSQL successfully computes a result. This is due to the
  26. # precision of our numeric types vs. the algorithm used to calculate
  27. # standard deviation (https://github.com/MaterializeInc/database-issues/issues/436).
  28. query error
  29. SELECT
  30. stddev_samp(decimal_39_8_val)
  31. FROM
  32. t_19511_case_3
  33. WHERE row_index IN (3, 4);
  34. query error
  35. SELECT
  36. stddev_samp(decimal_39_8_val)
  37. FROM
  38. WHERE row_index IN (3, 4);
  39. v_19511_case_3
  40. statement ok
  41. CREATE TABLE t_19511_case_4 (row_index INT, int8_val INT8);
  42. statement ok
  43. INSERT INTO t_19511_case_4 VALUES (5, 0::INT8);
  44. statement ok
  45. INSERT INTO t_19511_case_4 VALUES (7, 9223372036854775807::INT8);
  46. statement ok
  47. CREATE OR REPLACE VIEW v_19511_case_4 (row_index, int8_val)
  48. AS SELECT 5, 0::INT8
  49. UNION SELECT 7, 9223372036854775807::INT8;
  50. query R
  51. SELECT
  52. stddev_pop(int8_val)
  53. FROM
  54. t_19511_case_4
  55. WHERE row_index IN (5, 7);
  56. ----
  57. 4611686018427387903.50000000000000000001
  58. query R
  59. SELECT
  60. stddev_pop(int8_val)
  61. FROM
  62. v_19511_case_4
  63. WHERE row_index IN (5, 7);
  64. ----
  65. 4611686018427387903.50000000000000000001
  66. statement ok
  67. CREATE TABLE t_19511_case_6 (row_index INT, decimal_39_8_val DECIMAL(39,8));
  68. statement ok
  69. INSERT INTO t_19511_case_6 VALUES (6, 1.00000001::DECIMAL(39,8));
  70. statement ok
  71. INSERT INTO t_19511_case_6 VALUES (8, 0.99999999::DECIMAL(39,8));
  72. statement ok
  73. CREATE OR REPLACE VIEW v_19511_case_6 (row_index, decimal_39_8_val)
  74. AS SELECT 6, 1.00000001::DECIMAL(39,8)
  75. UNION SELECT 8, 0.99999999::DECIMAL(39,8);
  76. query R
  77. SELECT
  78. stddev_pop(decimal_39_8_val)
  79. FROM
  80. t_19511_case_6
  81. WHERE row_index IN (8, 6);
  82. ----
  83. 0.00000001
  84. query R
  85. SELECT
  86. stddev_pop(decimal_39_8_val)
  87. FROM
  88. v_19511_case_6
  89. WHERE row_index IN (8, 6);
  90. ----
  91. 0.00000001