github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/logictest/testdata/logic_test/typing (about) 1 # LogicTest: local 2 3 statement ok 4 CREATE TABLE f (x FLOAT) 5 6 statement ok 7 INSERT INTO f(x) VALUES (1e10000 * 1e-9999), (3/2), (1) 8 9 query R rowsort 10 SELECT * FROM f 11 ---- 12 10 13 1.5 14 1 15 16 statement ok 17 CREATE TABLE i (x INT) 18 19 statement error value type decimal doesn't match type int of column "x" 20 INSERT INTO i(x) VALUES (4.5) 21 22 statement ok 23 INSERT INTO i(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6) 24 25 statement error numeric constant out of int64 range 26 INSERT INTO i(x) VALUES (9223372036854775809) 27 28 query I rowsort 29 SELECT * FROM i 30 ---- 31 1 32 2 33 7 34 35 statement ok 36 CREATE TABLE d (x DECIMAL) 37 38 statement ok 39 INSERT INTO d(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6) 40 41 query R rowsort 42 SELECT * FROM d 43 ---- 44 1 45 2.0 46 7 47 48 statement ok 49 UPDATE d SET x = x + 1 WHERE x + sqrt(x) >= 2 + .1 50 51 query R rowsort 52 SELECT * FROM d 53 ---- 54 1 55 3.0 56 8 57 58 statement ok 59 CREATE TABLE s (x STRING) 60 61 query T 62 SELECT * FROM s WHERE x > b'\x00' 63 ---- 64 65 statement ok 66 INSERT INTO s(x) VALUES (b'qwe'), ('start' || b'end') 67 68 statement ok 69 INSERT INTO s(x) VALUES (b'\xfffefd') 70 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 78 statement error incompatible COALESCE expressions: could not parse "foo" as type int 79 INSERT INTO s VALUES (COALESCE(1, 'foo')) 80 81 statement error incompatible COALESCE expressions: could not parse "foo" as type int 82 INSERT INTO i VALUES (COALESCE(1, 'foo')) 83 84 query error incompatible COALESCE expressions: could not parse "foo" as type int 85 SELECT COALESCE(1, 'foo') 86 87 query error incompatible COALESCE expressions: could not parse "foo" as type int 88 SELECT COALESCE(1::INT, 'foo') 89 90 query R 91 SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4)) 92 ---- 93 123456789 94 95 query T 96 SELECT greatest('2010-09-29', '2010-09-28'::TIMESTAMP) 97 ---- 98 2010-09-29 00:00:00 +0000 +0000 99 100 query T 101 SELECT greatest('PT12H2M', 'PT12H2M'::INTERVAL, '1s') 102 ---- 103 12:02:00 104 105 # This is a current limitation where a nested constant that does not get folded (eg. abs(-9)) 106 # will not be exposed to the same constant type resolution rules as other constants, meaning that 107 # it may miss out on being upcast. The limitation could be addressed by either improving the 108 # scope of constant folding or improving homogeneous type resolution. 109 # TODO(nvanbenschoten) We may be able to address this by desiring the commonNumericConstantType 110 # of all constants for the first resolvableExpr in typeCheckSameTypedExprs when the parent 111 # expression has no desired type. 112 query error greatest\(\): expected -1.123 to be of type int, found type decimal 113 SELECT greatest(-1.123, 1.21313, 2.3, 123456789.321, 3 + 5.3213, -(-4.3213), abs(-9)) 114 115 query R 116 SELECT greatest(-1, 1, 2.3, 123456789, 3 + 5, -(-4), abs(-9.0)) 117 ---- 118 123456789 119 120 statement ok 121 CREATE TABLE untyped (b bool, n INT, f FLOAT, e DECIMAL, d DATE, ts TIMESTAMP, tz TIMESTAMPTZ, i INTERVAL) 122 123 statement ok 124 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') 125 126 query BIRRTTTT 127 SELECT * FROM untyped 128 ---- 129 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 130 131 # Issue #14527: support string literal coercion during overload resolution 132 query T 133 SELECT ts FROM untyped WHERE ts != '2015-09-18 00:00:00' 134 ---- 135 2010-09-28 12:00:00.1 +0000 +0000 136 137 # Regression tests for #15050 138 139 statement error pq: parsing as type timestamp: could not parse "Not Timestamp" 140 CREATE TABLE t15050a (c DECIMAL DEFAULT CASE WHEN now() < 'Not Timestamp' THEN 2 ELSE 2 END); 141 142 statement error pq: parsing as type timestamp: could not parse "Not Timestamp" 143 CREATE TABLE t15050b (c DECIMAL DEFAULT IF(now() < 'Not Timestamp', 2, 2)); 144 145 # Regression tests for #15632 146 147 statement error incompatible IFNULL expressions: could not parse "foo" as type bool 148 SELECT IFNULL('foo', false) 149 150 statement error incompatible IFNULL expressions: could not parse "foo" as type bool 151 SELECT IFNULL(true, 'foo') 152 153 query B 154 SELECT IFNULL(false, 'true') 155 ---- 156 false 157 158 query B 159 SELECT IFNULL('true', false) 160 ---- 161 true 162 163 # Regression tests for #19770 164 165 query B 166 SELECT 1 in (SELECT 1) 167 ---- 168 true 169 170 statement error could not parse "a" as type int 171 SELECT 1 IN (SELECT 'a') 172 173 statement error unsupported comparison operator: <int> IN <tuple{tuple{int, int}}> 174 SELECT 1 IN (SELECT (1, 2)) 175 176 query B 177 SELECT (1, 2) IN (SELECT 1, 2) 178 ---- 179 true 180 181 query B 182 SELECT (1, 2) IN (SELECT (1, 2)) 183 ---- 184 true 185 186 statement ok 187 CREATE TABLE t1 (a DATE) 188 189 statement ok 190 CREATE TABLE t2 (b TIMESTAMPTZ) 191 192 statement ok 193 INSERT INTO t1 VALUES (DATE '2018-01-01'); INSERT INTO t2 VALUES (TIMESTAMPTZ '2018-01-01'); 194 195 # Make sure that we do not create invalid filters due to substituting columns 196 # with different types. 197 query TT 198 SELECT * FROM t1, t2 WHERE a = b AND age(b, TIMESTAMPTZ '2017-01-01') > INTERVAL '1 day' 199 ---- 200 2018-01-01 00:00:00 +0000 +0000 2018-01-01 00:00:00 +0000 UTC 201 202 # Regression test for #44181: allow left side of BETWEEN to be typed 203 # differently in the two comparisons. 204 query B 205 SELECT '' BETWEEN ''::BYTES AND ''; 206 ---- 207 true 208 209 # Regression test for #44632: NULLIF should have the type of the first argument. 210 query I 211 SELECT NULLIF(NULL, 0) + NULLIF(NULL, 0) 212 ---- 213 NULL 214 215 query I 216 SELECT NULLIF(0, 0) + NULLIF(0, 0) 217 ---- 218 NULL 219 220 query I 221 SELECT NULLIF(0, NULL) + NULLIF(0, NULL) 222 ---- 223 0 224 225 # Regression test for #46196. 226 query T 227 SELECT max(t0.c0) FROM (VALUES (NULL), (NULL)) t0(c0) 228 ---- 229 NULL 230 231 query T 232 SELECT max(NULL) FROM (VALUES (NULL), (NULL)) t0(c0) 233 ---- 234 NULL 235 236 # Test qualified type references. 237 query IITR 238 SELECT 1::pg_catalog.int4, 1::pg_catalog.int8, 'aa'::pg_catalog.text, 4.2::pg_catalog.float4 239 ---- 240 1 1 aa 4.2 241 242 # Test that we error out referencing unknown types in pg_catalog. 243 query error pq: type "pg_catalog.special_int" does not exist 244 SELECT 1::pg_catalog.special_int 245 246 # Test that we error out trying to reference types in schemas that 247 # don't have types. 248 query error pq: type "crdb_internal.mytype" does not exist 249 SELECT 1::crdb_internal.mytype