conditional.slt 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. # Copyright 2015 - 2019 The Cockroach Authors. All rights reserved.
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # This file is derived from the logic test suite in CockroachDB. The
  12. # original file was retrieved on June 10, 2019 from:
  13. #
  14. # https://github.com/cockroachdb/cockroach/blob/d2f7fbf5dd1fc1a099bbad790a2e1f7c60a66cc3/pkg/sql/logictest/testdata/logic_test/conditional
  15. #
  16. # The original source code is subject to the terms of the Apache
  17. # 2.0 license, a copy of which can be found in the LICENSE file at the
  18. # root of this repository.
  19. mode cockroach
  20. query II
  21. SELECT IF(1 = 2, NULL, 1), IF(2 = 2, NULL, 2)
  22. ----
  23. 1 NULL
  24. query III
  25. SELECT NULLIF(1, 2), NULLIF(2, 2), NULLIF(NULL, NULL)
  26. ----
  27. 1 NULL NULL
  28. query IIII
  29. SELECT
  30. IFNULL(1, 2),
  31. IFNULL(NULL, 2),
  32. COALESCE(1, 2),
  33. COALESCE(NULL, 2)
  34. ----
  35. 1 2 1 2
  36. statement ok
  37. CREATE TABLE t (a) AS VALUES (1), (2), (3)
  38. query IT
  39. SELECT
  40. a,
  41. CASE
  42. WHEN a = 1 THEN 'one'
  43. WHEN a = 2 THEN 'two'
  44. ELSE 'other'
  45. END
  46. FROM
  47. t
  48. ORDER BY
  49. a
  50. ----
  51. 1 one
  52. 2 two
  53. 3 other
  54. query IT
  55. SELECT
  56. a,
  57. CASE a
  58. WHEN 1 THEN 'one'
  59. WHEN 2 THEN 'two'
  60. ELSE 'other'
  61. END
  62. FROM
  63. t
  64. ORDER BY
  65. a
  66. ----
  67. 1 one
  68. 2 two
  69. 3 other
  70. query III
  71. SELECT a, NULLIF(a, 2), IF(a = 2, NULL, a) FROM t ORDER BY a
  72. ----
  73. 1 1 1
  74. 2 NULL NULL
  75. 3 3 3
  76. query TTTT
  77. SELECT
  78. CASE
  79. WHEN false THEN 'one'
  80. WHEN true THEN 'two'
  81. ELSE 'three'
  82. END,
  83. CASE 1
  84. WHEN 2 THEN 'two'
  85. WHEN 1 THEN 'one'
  86. ELSE 'three'
  87. END,
  88. CASE
  89. WHEN false THEN 'one'
  90. ELSE 'three'
  91. END,
  92. CASE
  93. WHEN false THEN 'one'
  94. END
  95. ----
  96. two one three NULL
  97. query TTTTT
  98. SELECT
  99. CASE
  100. WHEN 1 = 1 THEN 'one'
  101. END,
  102. CASE false
  103. WHEN 0 = 1 THEN 'one'
  104. END,
  105. CASE 1
  106. WHEN 2 THEN 'one'
  107. ELSE 'three'
  108. END,
  109. CASE NULL
  110. WHEN true THEN 'one'
  111. WHEN false THEN 'two'
  112. WHEN NULL THEN 'three'
  113. ELSE 'four'
  114. END,
  115. CASE
  116. WHEN false THEN 'one'
  117. WHEN true THEN 'two'
  118. END
  119. ----
  120. one one three four two