typing.slt 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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/typing
  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. statement ok
  21. CREATE TABLE f (x FLOAT)
  22. statement ok
  23. INSERT INTO f(x) VALUES (1e10000 * 1e-9999), (3/2), (1)
  24. query R rowsort
  25. SELECT * FROM f
  26. ----
  27. 10
  28. 1.5
  29. 1
  30. statement ok
  31. CREATE TABLE i (x INT)
  32. statement error value type decimal doesn't match type int of column "x"
  33. INSERT INTO i(x) VALUES (4.5)
  34. statement ok
  35. INSERT INTO i(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6)
  36. statement error numeric constant out of int64 range
  37. INSERT INTO i(x) VALUES (9223372036854775809)
  38. query I rowsort
  39. SELECT * FROM i
  40. ----
  41. 1
  42. 2
  43. 7
  44. statement ok
  45. CREATE TABLE d (x DECIMAL)
  46. statement ok
  47. INSERT INTO d(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6)
  48. query R rowsort
  49. SELECT * FROM d
  50. ----
  51. 1
  52. 2.0
  53. 7
  54. statement ok
  55. UPDATE d SET x = x + 1 WHERE x + sqrt(x) >= 2 + .1
  56. query R rowsort
  57. SELECT * FROM d
  58. ----
  59. 1
  60. 3.0
  61. 8
  62. statement ok
  63. CREATE TABLE s (x STRING)
  64. query T
  65. SELECT * FROM s WHERE x > b'\x00'
  66. ----
  67. statement ok
  68. INSERT INTO s(x) VALUES (b'qwe'), ('start' || b'end')
  69. statement ok
  70. INSERT INTO s(x) VALUES (b'\xfffefd')
  71. query IT rowsort
  72. SELECT length(x), encode(x::bytes, 'escape') from s
  73. ----
  74. 3 qwe
  75. 8 startend
  76. 5 \377fefd
  77. statement error incompatible COALESCE expressions: could not parse "foo" as type int
  78. INSERT INTO s VALUES (COALESCE(1, 'foo'))
  79. statement error incompatible COALESCE expressions: could not parse "foo" as type int
  80. INSERT INTO i VALUES (COALESCE(1, 'foo'))
  81. query error incompatible COALESCE expressions: could not parse "foo" as type int
  82. SELECT COALESCE(1, 'foo')
  83. query error incompatible COALESCE expressions: could not parse "foo" as type int
  84. SELECT COALESCE(1::INT, 'foo')
  85. query R
  86. SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4))
  87. ----
  88. 123456789
  89. query T
  90. SELECT greatest('2010-09-29', '2010-09-28'::TIMESTAMP)
  91. ----
  92. 2010-09-29 00:00:00 +0000 +0000
  93. query T
  94. SELECT greatest('PT12H2M', 'PT12H2M'::INTERVAL, '1s')
  95. ----
  96. 12:02:00
  97. # This is a current limitation where a nested constant that does not get folded (eg. abs(-9))
  98. # will not be exposed to the same constant type resolution rules as other constants, meaning that
  99. # it may miss out on being upcast. The limitation could be addressed by either improving the
  100. # scope of constant folding or improving homogeneous type resolution.
  101. # TODO(nvanbenschoten) We may be able to address this by desiring the commonNumericConstantType
  102. # of all constants for the first resolvableExpr in typeCheckSameTypedExprs when the parent
  103. # expression has no desired type.
  104. query error greatest\(\): expected -1.123 to be of type int, found type decimal
  105. SELECT greatest(-1.123, 1.21313, 2.3, 123456789.321, 3 + 5.3213, -(-4.3213), abs(-9))
  106. query R
  107. SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4), abs(-9.0))
  108. ----
  109. 123456789
  110. statement ok
  111. CREATE TABLE untyped (b bool, n INT, f FLOAT, e DECIMAL, d DATE, ts TIMESTAMP, tz TIMESTAMPTZ, i INTERVAL)
  112. statement ok
  113. INSERT INTO untyped VALUES ('f', '42', '4.2', '4.20', '2010-09-28', '2010-09-28 12:00:00.1', '2010-09-29 12:00:00.1', 'PT12H2M')
  114. query BIRRTTTT
  115. SELECT * FROM untyped
  116. ----
  117. false 42 4.2 4.20 2010-09-28 00:00:00 +0000 +0000 2010-09-28 12:00:00.1 +0000 +0000 2010-09-29 12:00:00.1 +0000 UTC 12:02:00
  118. # Issue materialize#14527: support string literal coercion during overload resolution
  119. query T
  120. SELECT ts FROM untyped WHERE ts != '2015-09-18 00:00:00'
  121. ----
  122. 2010-09-28 12:00:00.1 +0000 +0000
  123. # Regression tests for materialize#15050
  124. statement error unsupported comparison operator: <timestamptz> < <string>
  125. CREATE TABLE t15050a (c DECIMAL DEFAULT CASE WHEN now() < 'Not Timestamp' THEN 2 ELSE 2 END);
  126. statement error unsupported comparison operator: <timestamptz> < <string>
  127. CREATE TABLE t15050b (c DECIMAL DEFAULT IF(now() < 'Not Timestamp', 2, 2));
  128. # Regression tests for materialize#15632
  129. statement error incompatible IFNULL expressions: could not parse "foo" as type bool
  130. SELECT IFNULL('foo', false)
  131. statement error incompatible IFNULL expressions: could not parse "foo" as type bool
  132. SELECT IFNULL(true, 'foo')
  133. query B
  134. SELECT IFNULL(false, 'true')
  135. ----
  136. false
  137. query B
  138. SELECT IFNULL('true', false)
  139. ----
  140. true
  141. # Regression tests for materialize#19770
  142. query B
  143. SELECT 1 in (SELECT 1)
  144. ----
  145. true
  146. # The heuristic planner and the optimizer give different errors for this query.
  147. # Accept them both.
  148. statement error (unsupported comparison operator: <int> IN <tuple{string}>|could not parse "a" as type int)
  149. SELECT 1 IN (SELECT 'a')
  150. statement error unsupported comparison operator: <int> IN <tuple{tuple{int, int}}>
  151. SELECT 1 IN (SELECT (1, 2))
  152. query B
  153. SELECT (1, 2) IN (SELECT 1, 2)
  154. ----
  155. true
  156. query B
  157. SELECT (1, 2) IN (SELECT (1, 2))
  158. ----
  159. true
  160. statement ok
  161. CREATE TABLE t1 (a DATE)
  162. statement ok
  163. CREATE TABLE t2 (b TIMESTAMPTZ)
  164. statement ok
  165. INSERT INTO t1 VALUES (DATE '2018-01-01'); INSERT INTO t2 VALUES (TIMESTAMPTZ '2018-01-01');
  166. # Make sure that we do not create invalid filters due to substituting columns
  167. # with different types.
  168. query TT
  169. SELECT * FROM t1, t2 WHERE a = b AND age(b, TIMESTAMPTZ '2017-01-01') > INTERVAL '1 day'
  170. ----
  171. 2018-01-01 00:00:00 +0000 +0000 2018-01-01 00:00:00 +0000 UTC