# LogicTest: default

statement ok
CREATE TABLE f (x FLOAT)

statement ok
INSERT INTO f(x) VALUES (1e10000 * 1e-9999), (3/2), (1)

query R rowsort
SELECT * FROM f
----
10
1.5
1

statement ok
CREATE TABLE i (x INT)

statement error value type decimal doesn't match type INT of column "x"
INSERT INTO i(x) VALUES (4.5)

statement ok
INSERT INTO i(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6)

statement error numeric constant out of int64 range
INSERT INTO i(x) VALUES (9223372036854775809)

query I rowsort
SELECT * FROM i
----
1
2
7

statement ok
CREATE TABLE d (x DECIMAL)

statement ok
INSERT INTO d(x) VALUES (((9 / 3) * (1 / 3))), (2.0), (2.4 + 4.6)

query R rowsort
SELECT * FROM d
----
1
2.0
7

statement ok
UPDATE d SET x = x + 1 WHERE x + SQRT(x) >= 2 + .1

query R rowsort
SELECT * FROM d
----
1
3.0
8

statement ok
CREATE TABLE s (x STRING)

query T
SELECT * FROM s WHERE x > b'\x00'
----

statement ok
INSERT INTO s(x) VALUES (b'qwe'), ('start' || b'end')

statement error value type bytes doesn't match type STRING of column "x"
INSERT INTO s(x) VALUES (b'\xfffefd')

query T rowsort
SELECT * from s
----
qwe
startend

statement error incompatible COALESCE expressions: expected 1 to be of type string, found type int
INSERT INTO s VALUES (COALESCE(1, 'foo'))

statement error incompatible COALESCE expressions: expected 'foo' to be of type int, found type string
INSERT INTO i VALUES (COALESCE(1, 'foo'))

query error incompatible COALESCE expressions: expected 'foo' to be of type int, found type string
SELECT COALESCE(1, 'foo')

query error incompatible COALESCE expressions: expected 'foo' to be of type int, found type string
SELECT COALESCE(1::INT, 'foo')

query R
SELECT GREATEST(-1, 1, 2.3, 123456789, 3 + 5, -(-4))
----
123456789

query T
SELECT GREATEST('2010-09-29', '2010-09-28'::TIMESTAMP)
----
2010-09-29 00:00:00 +0000 +0000

query T
SELECT GREATEST('PT12H2M', 'PT12H2M'::INTERVAL, '1s')
----
12h2m

# This is a current limitation where a nested constant that does not get folded (eg. ABS(-9))
# will not be exposed to the same constant type resolution rules as other constants, meaning that
# it may miss out on being upcast. The limitation could be addressed by either improving the
# scope of constant folding or improving homogeneous type resolution.
# TODO(nvanbenschoten) We may be able to address this by desiring the commonNumericConstantType
#     of all constants for the first resolvableExpr in typeCheckSameTypedExprs when the parent
#     expression has no desired type.
query error greatest\(\): expected -1.123 to be of type int, found type decimal
SELECT GREATEST(-1.123, 1.21313, 2.3, 123456789.321, 3 + 5.3213, -(-4.3213), ABS(-9))

query R
SELECT GREATEST(-1, 1, 2.3, 123456789, 3 + 5, -(-4), ABS(-9.0))
----
123456789

statement ok
CREATE TABLE untyped (b bool, d DATE, ts TIMESTAMP, tz TIMESTAMPTZ, i INTERVAL)

statement ok
INSERT INTO untyped VALUES ('f', '2010-09-28', '2010-09-28 12:00:00.1', '2010-09-29 12:00:00.1', 'PT12H2M')

query BTTTT
SELECT * FROM untyped
----
false   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 +0000   12h2m

# Issue #14527: support string literal coercion during overload resolution
query T
SELECT ts FROM untyped WHERE ts != '2015-09-18 00:00:00'
----
2010-09-28 12:00:00.1 +0000 +0000

# Regression tests for #15050

statement error error type checking constant value: could not parse '2017-04-18 18:00' as type timestamp
CREATE TABLE t15050a (c DECIMAL DEFAULT CASE WHEN NOW() < '2017-04-18 18:00' THEN 2 ELSE 2 END);

statement error error type checking constant value: could not parse '2017-04-18 18:00' as type timestamp
CREATE TABLE t15050b (c DECIMAL DEFAULT IF(NOW() < '2017-04-18 18:00', 2, 2));

# Regression tests for #15632

statement error incompatible IFNULL expressions: could not parse 'foo' as type bool: strconv.ParseBool: parsing "foo": invalid syntax
SELECT IFNULL('foo', false)

statement error incompatible IFNULL expressions: could not parse 'foo' as type bool: strconv.ParseBool: parsing "foo": invalid syntax
SELECT IFNULL(true, 'foo')

query B
SELECT IFNULL(false, 'true')
----
false

query B
SELECT IFNULL('true', false)
----
true
