# LogicTest: local

statement ok
CREATE TABLE t (
  a INT PRIMARY KEY,
  b DECIMAL(10,1) NOT NULL DEFAULT(1000.15),
  c TEXT COLLATE en_US DEFAULT('empty' COLLATE en_US),
  d DECIMAL(10,2) NOT NULL,
  e TIME,
  f DECIMAL(10,1) AS (a + b + d) STORED,
  --UNIQUE INDEX t_secondary (c, d), -- Fails due to #46276
  FAMILY (a, b, c),
  FAMILY (d, e, f)
)

statement ok
INSERT INTO t VALUES (100, 500.5, 'stuff' COLLATE en_US, 600.6, '12:12:12')

# Drop all columns except "a" and perform interesting operations.
statement ok
BEGIN;
--DROP INDEX t_secondary CASCADE;
ALTER TABLE t DROP COLUMN f, DROP COLUMN b, DROP COLUMN c, DROP COLUMN d, DROP COLUMN e;
ALTER TABLE t ADD COLUMN g INT NOT NULL DEFAULT(15)

# Expect default values for b, c, zero value for d, and NULL value for e.
query T kvtrace(prefix=/Table/106/)
INSERT INTO t SELECT a + 1 FROM t
----
Scan /Table/106/{1-2}
CPut /Table/106/1/101/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
CPut /Table/106/1/101/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1101.2

# Expect default values for b, c, zero value for d, and NULL value for e.
query T kvtrace(prefix=/Table/106/)
UPSERT INTO t SELECT a + 1 FROM t
----
Scan /Table/106/{1-2}
Scan /Table/106/1/10{1-2}, /Table/106/1/10{2-3}
Put /Table/106/1/101/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
Put /Table/106/1/101/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1101.2
CPut /Table/106/1/102/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
CPut /Table/106/1/102/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1102.2

# Expect default values for b, c, zero value for d, and NULL value for e.
query T kvtrace(prefix=/Table/106/)
UPDATE t SET a = a + 100
----
Scan /Table/106/{1-2} lock Exclusive (Block, Unreplicated)
Del /Table/106/1/100/0
Del /Table/106/1/100/1/1
CPut /Table/106/1/200/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
CPut /Table/106/1/200/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1200.2
Del /Table/106/1/101/0
Del /Table/106/1/101/1/1
CPut /Table/106/1/201/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
CPut /Table/106/1/201/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1201.2
Del /Table/106/1/102/0
Del /Table/106/1/102/1/1
CPut /Table/106/1/202/0 -> /TUPLE/2:2:Decimal/1000.2/1:3:Bytes/empty
CPut /Table/106/1/202/1/1 -> /TUPLE/4:4:Decimal/0.00/2:6:Decimal/1202.2

statement ok
DELETE FROM t WHERE a=201

statement ok
COMMIT

query II rowsort
SELECT * FROM t
----
200  15
202  15
