# LogicTest: default parallel-stmts distsql

statement error incompatible type for DEFAULT expression: int vs bool
CREATE TABLE t (a INT PRIMARY KEY DEFAULT false)

statement error DEFAULT expression .* may not contain variable sub-expressions
CREATE TABLE t (a INT PRIMARY KEY DEFAULT $1)

statement error DEFAULT expression .* may not contain variable sub-expressions
CREATE TABLE t (a INT PRIMARY KEY DEFAULT (SELECT 1))

statement error DEFAULT expression .* may not contain variable sub-expressions
CREATE TABLE t (a INT PRIMARY KEY DEFAULT b)

# Issue #14308: support tables with DEFAULT NULL columns.
statement ok
CREATE TABLE null_default (ts TIMESTAMP PRIMARY KEY NULL DEFAULT NULL)

# Aggregate function calls in CHECK are not ok.
statement error aggregate functions are not allowed in DEFAULT expressions
CREATE TABLE bad (a INT DEFAULT COUNT(1))

# Window function calls in CHECK are not ok.
statement error window functions are not allowed in DEFAULT expressions
CREATE TABLE bad (a INT DEFAULT COUNT(1) OVER ())

statement ok
CREATE TABLE t (
  a INT PRIMARY KEY DEFAULT 42,
  b TIMESTAMP DEFAULT now(),
  c FLOAT DEFAULT random()
)

query TTBTT colnames
SHOW COLUMNS FROM t
----
Field Type      Null  Default  Indices
a     INT       false 42:::INT {primary}
b     TIMESTAMP true  now()    {}
c     FLOAT     true  random() {}

statement ok
INSERT INTO t VALUES (DEFAULT, DEFAULT, DEFAULT)

query IBB
SELECT a, b <= now(), c >= 0.0 FROM t
----
42 true true

statement ok
TRUNCATE TABLE t

statement ok
INSERT INTO t DEFAULT VALUES

query IBB
SELECT a, b <= now(), c >= 0.0 FROM t
----
42 true true

statement ok
INSERT INTO t (a) VALUES (1)

query IBB
SELECT a, b <= now(), c >= 0.0 FROM t WHERE a = 1
----
1 true true

statement ok
INSERT INTO t VALUES (2)

query IBB
SELECT a, b <= now(), c >= 0.0 FROM t WHERE a = 2
----
2 true true

statement ok
UPDATE t SET (b, c) = ('2015-09-18 00:00:00', -1.0)

statement ok
UPDATE t SET b = DEFAULT WHERE a = 1

query IBB
SELECT a, b <= now(), c = -1.0 FROM t WHERE a = 1
----
1 true true

statement ok
UPDATE t SET (b, c) = (DEFAULT, DEFAULT) WHERE a = 2

query IBB
SELECT a, b <= now(), c >= 0.0 FROM t WHERE a = 2
----
2 true true

statement ok
UPDATE t SET b = DEFAULT, c = DEFAULT

statement ok
UPDATE t SET (b) = (DEFAULT), (c) = (DEFAULT)

# Test a table without a default and with a null default
statement ok
CREATE TABLE v (
  a INT PRIMARY KEY,
  b TIMESTAMP NULL DEFAULT NULL,
  c INT
)

statement ok
UPDATE v SET a = DEFAULT

statement ok
UPDATE v SET (a, c) = (DEFAULT, DEFAULT)

query TTBTT colnames
SHOW COLUMNS FROM v
----
Field Type      Null  Default  Indices
a     INT       false NULL     {primary}
b     TIMESTAMP true  NULL     {}
c     INT       true  NULL     {}
