error_semantics.slt 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. # This file is for error semantics and evaluation order/short-circuiting, see
  10. # https://github.com/MaterializeInc/database-issues/issues/4972
  11. #
  12. ########################################################################################################################
  13. # NOTE: THESE EXPECTED RESULTS ARE NOT SET IN STONE! The results, together with occasional comments above them, are our
  14. # current best guess of what our error semantics will be, but it's ok to change this for now as we learn more.
  15. ########################################################################################################################
  16. statement ok
  17. create table test (a int, b int);
  18. statement ok
  19. insert into test values (1, 0);
  20. query I
  21. select coalesce(a, 1/b) from test;
  22. ----
  23. 1
  24. # Postgres errors on it, which we consider to be a bug in Postgres, because Postgres' coalesce docs say it should
  25. # short-circuit: https://www.postgresql.org/docs/current/functions-conditional.html#FUNCTIONS-COALESCE-NVL-IFNULL
  26. query I
  27. select coalesce(a, 1/0) from test;
  28. ----
  29. 1
  30. query I
  31. select coalesce(a, 1/b) from test where b = 0;
  32. ----
  33. 1
  34. query I
  35. select coalesce(7, 1/b) from test;
  36. ----
  37. 7
  38. query I
  39. select coalesce(7, 1/0) from test;
  40. ----
  41. 7
  42. statement ok
  43. create table test_nonnull (a int not null, b int);
  44. statement ok
  45. insert into test_nonnull values (1, 0);
  46. query I
  47. select coalesce(a, 1/b) from test_nonnull;
  48. ----
  49. 1
  50. # Postgres errors, which we consider to be a bug in Postgres
  51. query I
  52. select coalesce(a, 1/0) from test_nonnull;
  53. ----
  54. 1
  55. query I
  56. select coalesce(a, 1/b) from test_nonnull where b = 0;
  57. ----
  58. 1
  59. query I
  60. select coalesce(7, 1/b) from test_nonnull;
  61. ----
  62. 7
  63. query I
  64. select coalesce(7, 1/0) from test_nonnull;
  65. ----
  66. 7
  67. # MFP CSE, see https://github.com/MaterializeInc/materialize/pull/33109
  68. query I
  69. select coalesce(a, a/b + 1, a/b + 2) from test;
  70. ----
  71. 1
  72. # The following two results are probably wrong (but depends on what error semantics we agree on later).
  73. query error db error: ERROR: Evaluation error: division by zero
  74. select coalesce(a, (select a/b from test)) from test;
  75. query error db error: ERROR: Evaluation error: division by zero
  76. select *, case when a = 5 then (select a/b from test) else 7 end from test;