exec-ddl
CREATE TABLE abcde (
    a INT NOT NULL,
    b INT,
    c INT DEFAULT (10),
    d INT AS (abcde.b + c + 1) STORED,
    e INT AS (a) STORED
)
----
TABLE abcde
 ├── a int not null
 ├── b int
 ├── c int
 ├── d int
 ├── e int
 ├── rowid int not null (hidden)
 └── INDEX primary
      └── rowid int not null (hidden)

exec-ddl
CREATE TABLE xyz (
    x TEXT PRIMARY KEY,
    y INT8,
    z FLOAT8
)
----
TABLE xyz
 ├── x string not null
 ├── y int
 ├── z float
 └── INDEX primary
      └── x string not null

exec-ddl
CREATE TABLE uv (
    u DECIMAL,
    v BYTES
)
----
TABLE uv
 ├── u decimal
 ├── v bytes
 ├── rowid int not null (hidden)
 └── INDEX primary
      └── rowid int not null (hidden)

exec-ddl
CREATE TABLE mutation (
    m INT PRIMARY KEY,
    n INT,
    "o:write-only" INT DEFAULT(10),
    "p:write-only" INT AS (o + n) STORED,
    "q:delete-only" INT AS (m * p) STORED,
    CHECK (m > 0)
)
----
TABLE mutation
 ├── m int not null
 ├── n int
 ├── o int (mutation)
 ├── p int (mutation)
 ├── q int (mutation)
 ├── INDEX primary
 │    └── m int not null
 └── CHECK (m > 0)

exec-ddl
CREATE TABLE checks (
    a INT PRIMARY KEY CHECK (a > 0),
    b INT,
    c INT,
    d INT AS (c + 1) STORED,
    CHECK (checks.b < d)
)
----
TABLE checks
 ├── a int not null
 ├── b int
 ├── c int
 ├── d int
 ├── INDEX primary
 │    └── a int not null
 ├── CHECK (checks.b < d)
 └── CHECK (a > 0)

exec-ddl
CREATE TABLE decimals (
    a DECIMAL(10,0) PRIMARY KEY CHECK (round(a) = a),
    b DECIMAL(5,1)[] CHECK (b[0] > 1),
    c DECIMAL(10,1) DEFAULT (1.23),
    d DECIMAL(10,1) AS (a+c) STORED
)
----
TABLE decimals
 ├── a decimal not null
 ├── b decimal[]
 ├── c decimal
 ├── d decimal
 ├── INDEX primary
 │    └── a decimal not null
 ├── CHECK (round(a) = a)
 └── CHECK (b[0] > 1)

# Unknown target table.
build
INSERT INTO unknown VALUES (1, 2, 3)
----
error: no data source matches prefix: "unknown"

# ------------------------------------------------------------------------------
# Tests without target column names.
# ------------------------------------------------------------------------------

# Specify values for all non-hidden columns.
build
INSERT INTO abcde VALUES (1, 2, 3)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column2:8 => b:2
 │    ├──  column3:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column3:9(int) column10:10(int)
      ├── project
      │    ├── columns: column10:10(int) column1:7(int) column2:8(int) column3:9(int)
      │    ├── values
      │    │    ├── columns: column1:7(int) column2:8(int) column3:9(int)
      │    │    └── tuple [type=tuple{int, int, int}]
      │    │         ├── const: 1 [type=int]
      │    │         ├── const: 2 [type=int]
      │    │         └── const: 3 [type=int]
      │    └── projections
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column2 [type=int]
                │    └── variable: column3 [type=int]
                └── const: 1 [type=int]

# Don't specify values for null or default columns.
build
INSERT INTO abcde VALUES (1)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column8:8 => b:2
 │    ├──  column9:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column8:8(int) column9:9(int!null) column10:10(int)
      ├── project
      │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) column1:7(int)
      │    ├── values
      │    │    ├── columns: column1:7(int)
      │    │    └── tuple [type=tuple{int}]
      │    │         └── const: 1 [type=int]
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column8 [type=int]
                │    └── variable: column9 [type=int]
                └── const: 1 [type=int]

# Ordered input.
build
INSERT INTO abcde SELECT y FROM xyz ORDER BY y, z LIMIT 10
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  y:8 => a:1
 │    ├──  column10:10 => b:2
 │    ├──  column11:11 => c:3
 │    ├──  column13:13 => d:4
 │    ├──  y:8 => e:5
 │    └──  column12:12 => rowid:6
 └── project
      ├── columns: column13:13(int) y:8(int) column10:10(int) column11:11(int!null) column12:12(int)
      ├── project
      │    ├── columns: column10:10(int) column11:11(int!null) column12:12(int) y:8(int)
      │    ├── limit
      │    │    ├── columns: y:8(int) z:9(float)
      │    │    ├── internal-ordering: +8,+9
      │    │    ├── sort
      │    │    │    ├── columns: y:8(int) z:9(float)
      │    │    │    ├── ordering: +8,+9
      │    │    │    └── project
      │    │    │         ├── columns: y:8(int) z:9(float)
      │    │    │         └── scan xyz
      │    │    │              └── columns: x:7(string!null) y:8(int) z:9(float)
      │    │    └── const: 10 [type=int]
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column10 [type=int]
                │    └── variable: column11 [type=int]
                └── const: 1 [type=int]

# Ignore ORDER BY without LIMIT.
build
INSERT INTO abcde SELECT y FROM xyz ORDER BY y, z
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  y:8 => a:1
 │    ├──  column10:10 => b:2
 │    ├──  column11:11 => c:3
 │    ├──  column13:13 => d:4
 │    ├──  y:8 => e:5
 │    └──  column12:12 => rowid:6
 └── project
      ├── columns: column13:13(int) y:8(int) column10:10(int) column11:11(int!null) column12:12(int)
      ├── project
      │    ├── columns: column10:10(int) column11:11(int!null) column12:12(int) y:8(int)
      │    ├── project
      │    │    ├── columns: y:8(int) z:9(float)
      │    │    └── scan xyz
      │    │         └── columns: x:7(string!null) y:8(int) z:9(float)
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column10 [type=int]
                │    └── variable: column11 [type=int]
                └── const: 1 [type=int]

# Use placeholders.
build
INSERT INTO xyz VALUES ($1, $2, $3)
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:4 => x:1
 │    ├──  column2:5 => y:2
 │    └──  column3:6 => z:3
 └── values
      ├── columns: column1:4(string) column2:5(int) column3:6(float)
      └── tuple [type=tuple{string, int, float}]
           ├── placeholder: $1 [type=string]
           ├── placeholder: $2 [type=int]
           └── placeholder: $3 [type=float]

# Null expressions.
build
INSERT INTO abcde VALUES (2, null, null)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column2:8 => b:2
 │    ├──  column3:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column3:9(int) column10:10(int)
      ├── project
      │    ├── columns: column10:10(int) column1:7(int) column2:8(int) column3:9(int)
      │    ├── values
      │    │    ├── columns: column1:7(int) column2:8(int) column3:9(int)
      │    │    └── tuple [type=tuple{int, int, int}]
      │    │         ├── const: 2 [type=int]
      │    │         ├── cast: INT8 [type=int]
      │    │         │    └── null [type=unknown]
      │    │         └── cast: INT8 [type=int]
      │    │              └── null [type=unknown]
      │    └── projections
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column2 [type=int]
                │    └── variable: column3 [type=int]
                └── const: 1 [type=int]

# Duplicate expressions.
build
INSERT INTO abcde SELECT 2, $1 + 1, $1 + 1
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  "?column?":7 => a:1
 │    ├──  "?column?":8 => b:2
 │    ├──  "?column?":8 => c:3
 │    ├──  column10:10 => d:4
 │    ├──  "?column?":7 => e:5
 │    └──  column9:9 => rowid:6
 └── project
      ├── columns: column10:10(int) "?column?":7(int!null) "?column?":8(int) column9:9(int)
      ├── project
      │    ├── columns: column9:9(int) "?column?":7(int!null) "?column?":8(int)
      │    ├── project
      │    │    ├── columns: "?column?":7(int!null) "?column?":8(int)
      │    │    ├── values
      │    │    │    └── tuple [type=tuple]
      │    │    └── projections
      │    │         ├── const: 2 [type=int]
      │    │         └── plus [type=int]
      │    │              ├── placeholder: $1 [type=int]
      │    │              └── const: 1 [type=int]
      │    └── projections
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: ?column? [type=int]
                │    └── variable: ?column? [type=int]
                └── const: 1 [type=int]

# Use DEFAULT VALUES.
build
INSERT INTO uv DEFAULT VALUES
----
insert uv
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column4:4 => u:1
 │    ├──  column5:5 => v:2
 │    └──  column6:6 => rowid:3
 └── project
      ├── columns: column4:4(decimal) column5:5(bytes) column6:6(int)
      ├── values
      │    └── tuple [type=tuple]
      └── projections
           ├── cast: DECIMAL [type=decimal]
           │    └── null [type=unknown]
           ├── cast: BYTES [type=bytes]
           │    └── null [type=unknown]
           └── function: unique_rowid [type=int]

# Use DEFAULT expressions in VALUES expression.
build
INSERT INTO abcde ((VALUES (1, DEFAULT, 2), (2, 3, 4), (3, 2, DEFAULT), (4, DEFAULT, DEFAULT)))
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column2:8 => b:2
 │    ├──  column3:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column3:9(int) column10:10(int)
      ├── project
      │    ├── columns: column10:10(int) column1:7(int) column2:8(int) column3:9(int)
      │    ├── values
      │    │    ├── columns: column1:7(int) column2:8(int) column3:9(int)
      │    │    ├── tuple [type=tuple{int, int, int}]
      │    │    │    ├── const: 1 [type=int]
      │    │    │    ├── cast: INT8 [type=int]
      │    │    │    │    └── null [type=unknown]
      │    │    │    └── const: 2 [type=int]
      │    │    ├── tuple [type=tuple{int, int, int}]
      │    │    │    ├── const: 2 [type=int]
      │    │    │    ├── const: 3 [type=int]
      │    │    │    └── const: 4 [type=int]
      │    │    ├── tuple [type=tuple{int, int, int}]
      │    │    │    ├── const: 3 [type=int]
      │    │    │    ├── const: 2 [type=int]
      │    │    │    └── const: 10 [type=int]
      │    │    └── tuple [type=tuple{int, int, int}]
      │    │         ├── const: 4 [type=int]
      │    │         ├── cast: INT8 [type=int]
      │    │         │    └── null [type=unknown]
      │    │         └── const: 10 [type=int]
      │    └── projections
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column2 [type=int]
                │    └── variable: column3 [type=int]
                └── const: 1 [type=int]

# Use DEFAULT expressions in VALUES expression wrapped by WITH clause (error).
build
INSERT INTO abcde WITH a AS (SELECT 1) VALUES (1, DEFAULT, 2)
----
error (42601): DEFAULT can only appear in a VALUES list within INSERT or on the right side of a SET

# Too many values.
build
INSERT INTO xyz VALUES ('foo', 2, 3, 4)
----
error (42601): INSERT has more expressions than target columns, 4 expressions for 3 targets

# Return values from insert.
build
INSERT INTO abcde SELECT 1 RETURNING *
----
project
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int!null)
 └── insert abcde
      ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int!null) rowid:6(int!null)
      ├── insert-mapping:
      │    ├──  "?column?":7 => a:1
      │    ├──  column8:8 => b:2
      │    ├──  column9:9 => c:3
      │    ├──  column11:11 => d:4
      │    ├──  "?column?":7 => e:5
      │    └──  column10:10 => rowid:6
      └── project
           ├── columns: column11:11(int) "?column?":7(int!null) column8:8(int) column9:9(int!null) column10:10(int)
           ├── project
           │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) "?column?":7(int!null)
           │    ├── project
           │    │    ├── columns: "?column?":7(int!null)
           │    │    ├── values
           │    │    │    └── tuple [type=tuple]
           │    │    └── projections
           │    │         └── const: 1 [type=int]
           │    └── projections
           │         ├── cast: INT8 [type=int]
           │         │    └── null [type=unknown]
           │         ├── const: 10 [type=int]
           │         └── function: unique_rowid [type=int]
           └── projections
                └── plus [type=int]
                     ├── plus [type=int]
                     │    ├── variable: column8 [type=int]
                     │    └── variable: column9 [type=int]
                     └── const: 1 [type=int]

# Return values from aliased table.
build
INSERT INTO abcde AS foo SELECT 1 RETURNING foo.a + 1, foo.b * foo.c
----
project
 ├── columns: "?column?":12(int) "?column?":13(int)
 ├── insert foo
 │    ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int!null) rowid:6(int!null)
 │    ├── insert-mapping:
 │    │    ├──  "?column?":7 => a:1
 │    │    ├──  column8:8 => b:2
 │    │    ├──  column9:9 => c:3
 │    │    ├──  column11:11 => d:4
 │    │    ├──  "?column?":7 => e:5
 │    │    └──  column10:10 => rowid:6
 │    └── project
 │         ├── columns: column11:11(int) "?column?":7(int!null) column8:8(int) column9:9(int!null) column10:10(int)
 │         ├── project
 │         │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) "?column?":7(int!null)
 │         │    ├── project
 │         │    │    ├── columns: "?column?":7(int!null)
 │         │    │    ├── values
 │         │    │    │    └── tuple [type=tuple]
 │         │    │    └── projections
 │         │    │         └── const: 1 [type=int]
 │         │    └── projections
 │         │         ├── cast: INT8 [type=int]
 │         │         │    └── null [type=unknown]
 │         │         ├── const: 10 [type=int]
 │         │         └── function: unique_rowid [type=int]
 │         └── projections
 │              └── plus [type=int]
 │                   ├── plus [type=int]
 │                   │    ├── variable: column8 [type=int]
 │                   │    └── variable: column9 [type=int]
 │                   └── const: 1 [type=int]
 └── projections
      ├── plus [type=int]
      │    ├── variable: a [type=int]
      │    └── const: 1 [type=int]
      └── mult [type=int]
           ├── variable: b [type=int]
           └── variable: c [type=int]

# Use returning INSERT as a FROM expression.
build
SELECT * FROM [INSERT INTO abcde VALUES (1) RETURNING *]
----
project
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int)
 └── insert abcde
      ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int) rowid:6(int!null)
      ├── insert-mapping:
      │    ├──  column1:7 => a:1
      │    ├──  column8:8 => b:2
      │    ├──  column9:9 => c:3
      │    ├──  column11:11 => d:4
      │    ├──  column1:7 => e:5
      │    └──  column10:10 => rowid:6
      └── project
           ├── columns: column11:11(int) column1:7(int) column8:8(int) column9:9(int!null) column10:10(int)
           ├── project
           │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) column1:7(int)
           │    ├── values
           │    │    ├── columns: column1:7(int)
           │    │    └── tuple [type=tuple{int}]
           │    │         └── const: 1 [type=int]
           │    └── projections
           │         ├── cast: INT8 [type=int]
           │         │    └── null [type=unknown]
           │         ├── const: 10 [type=int]
           │         └── function: unique_rowid [type=int]
           └── projections
                └── plus [type=int]
                     ├── plus [type=int]
                     │    ├── variable: column8 [type=int]
                     │    └── variable: column9 [type=int]
                     └── const: 1 [type=int]

# Try to use aggregate function in RETURNING clause.
build
INSERT INTO abcde VALUES (1) RETURNING sum(a)
----
error: sum(): aggregate functions are not allowed in RETURNING

# Try to use SRF in RETURNING clause.
build
INSERT INTO abcde VALUES (1) RETURNING generate_series(1, 10)
----
error: generate_series(): generator functions are not allowed in RETURNING

# Try to use non-returning INSERT as expression.
build
SELECT * FROM [INSERT INTO abcde VALUES (1)]
----
error (42703): statement source "INSERT INTO abcde VALUES (1)" does not return any columns

# Use CTE with multiple variables.
build
WITH a AS (SELECT y, y+1 FROM xyz) INSERT INTO abcde SELECT * FROM a
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  y:2 => a:5
 │    ├──  "?column?":4 => b:6
 │    ├──  column11:11 => c:7
 │    ├──  column13:13 => d:8
 │    ├──  y:2 => e:9
 │    └──  column12:12 => rowid:10
 └── project
      ├── columns: column13:13(int) y:2(int) "?column?":4(int) column11:11(int!null) column12:12(int)
      ├── project
      │    ├── columns: column11:11(int!null) column12:12(int) y:2(int) "?column?":4(int)
      │    ├── project
      │    │    ├── columns: "?column?":4(int) y:2(int)
      │    │    ├── scan xyz
      │    │    │    └── columns: x:1(string!null) y:2(int) z:3(float)
      │    │    └── projections
      │    │         └── plus [type=int]
      │    │              ├── variable: y [type=int]
      │    │              └── const: 1 [type=int]
      │    └── projections
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: ?column? [type=int]
                │    └── variable: column11 [type=int]
                └── const: 1 [type=int]

# Use CTE with multiple variables.
build
WITH a AS (SELECT y, y+1 FROM xyz), b AS (SELECT y+1, y FROM xyz)
INSERT INTO abcde TABLE a UNION TABLE b
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  y:15 => a:9
 │    ├──  "?column?":16 => b:10
 │    ├──  column17:17 => c:11
 │    ├──  column19:19 => d:12
 │    ├──  y:15 => e:13
 │    └──  column18:18 => rowid:14
 └── project
      ├── columns: column19:19(int) y:15(int) "?column?":16(int) column17:17(int!null) column18:18(int)
      ├── project
      │    ├── columns: column17:17(int!null) column18:18(int) y:15(int) "?column?":16(int)
      │    ├── union
      │    │    ├── columns: y:15(int) "?column?":16(int)
      │    │    ├── left columns: xyz.y:2(int) "?column?":4(int)
      │    │    ├── right columns: "?column?":8(int) xyz.y:6(int)
      │    │    ├── project
      │    │    │    ├── columns: "?column?":4(int) xyz.y:2(int)
      │    │    │    ├── scan xyz
      │    │    │    │    └── columns: x:1(string!null) xyz.y:2(int) z:3(float)
      │    │    │    └── projections
      │    │    │         └── plus [type=int]
      │    │    │              ├── variable: xyz.y [type=int]
      │    │    │              └── const: 1 [type=int]
      │    │    └── project
      │    │         ├── columns: "?column?":8(int) xyz.y:6(int)
      │    │         ├── scan xyz
      │    │         │    └── columns: x:5(string!null) xyz.y:6(int) z:7(float)
      │    │         └── projections
      │    │              └── plus [type=int]
      │    │                   ├── variable: xyz.y [type=int]
      │    │                   └── const: 1 [type=int]
      │    └── projections
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: ?column? [type=int]
                │    └── variable: column17 [type=int]
                └── const: 1 [type=int]

# Non-referenced CTE with mutation.
build
WITH cte AS (SELECT b FROM [INSERT INTO abcde VALUES (1) RETURNING *]) INSERT INTO abcde VALUES (1)
----
error (0A000): unimplemented: common table expression "cte" with side effects was not used in query

# Insert CTE that returns no columns.
build
WITH cte AS (INSERT INTO abcde VALUES (1)) SELECT * FROM cte
----
error (0A000): WITH clause "cte" does not have a RETURNING clause

# Use SRF in RETURNING clause.
build
INSERT INTO abcde VALUES (1) RETURNING generate_series(1, 100)
----
error: generate_series(): generator functions are not allowed in RETURNING

# Correlated subquery.
build
SELECT * FROM xyz WHERE EXISTS (SELECT * FROM [INSERT INTO abcde VALUES (y, y+1) RETURNING *])
----
select
 ├── columns: x:1(string!null) y:2(int) z:3(float)
 ├── scan xyz
 │    └── columns: x:1(string!null) y:2(int) z:3(float)
 └── filters
      └── exists [type=bool]
           └── project
                ├── columns: a:4(int!null) b:5(int) c:6(int!null) d:7(int) e:8(int)
                └── insert abcde
                     ├── columns: a:4(int!null) b:5(int) c:6(int!null) d:7(int) e:8(int) rowid:9(int!null)
                     ├── insert-mapping:
                     │    ├──  column1:10 => a:4
                     │    ├──  column2:11 => b:5
                     │    ├──  column12:12 => c:6
                     │    ├──  column14:14 => d:7
                     │    ├──  column1:10 => e:8
                     │    └──  column13:13 => rowid:9
                     └── project
                          ├── columns: column14:14(int) column1:10(int) column2:11(int) column12:12(int!null) column13:13(int)
                          ├── project
                          │    ├── columns: column12:12(int!null) column13:13(int) column1:10(int) column2:11(int)
                          │    ├── values
                          │    │    ├── columns: column1:10(int) column2:11(int)
                          │    │    └── tuple [type=tuple{int, int}]
                          │    │         ├── variable: y [type=int]
                          │    │         └── plus [type=int]
                          │    │              ├── variable: y [type=int]
                          │    │              └── const: 1 [type=int]
                          │    └── projections
                          │         ├── const: 10 [type=int]
                          │         └── function: unique_rowid [type=int]
                          └── projections
                               └── plus [type=int]
                                    ├── plus [type=int]
                                    │    ├── variable: column2 [type=int]
                                    │    └── variable: column12 [type=int]
                                    └── const: 1 [type=int]

# ------------------------------------------------------------------------------
# Tests with target column names.
# ------------------------------------------------------------------------------

# Specify values for all non-computed columns.
build
INSERT INTO abcde (c, b, a) VALUES (1, 2, 3)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column3:9 => a:1
 │    ├──  column2:8 => b:2
 │    ├──  column1:7 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column3:9 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column3:9(int) column10:10(int)
      ├── project
      │    ├── columns: column10:10(int) column1:7(int) column2:8(int) column3:9(int)
      │    ├── values
      │    │    ├── columns: column1:7(int) column2:8(int) column3:9(int)
      │    │    └── tuple [type=tuple{int, int, int}]
      │    │         ├── const: 1 [type=int]
      │    │         ├── const: 2 [type=int]
      │    │         └── const: 3 [type=int]
      │    └── projections
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column2 [type=int]
                │    └── variable: column1 [type=int]
                └── const: 1 [type=int]

# Don't specify values for null or default columns.
build
INSERT INTO abcde (a) VALUES (1)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column8:8 => b:2
 │    ├──  column9:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column8:8(int) column9:9(int!null) column10:10(int)
      ├── project
      │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) column1:7(int)
      │    ├── values
      │    │    ├── columns: column1:7(int)
      │    │    └── tuple [type=tuple{int}]
      │    │         └── const: 1 [type=int]
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column8 [type=int]
                │    └── variable: column9 [type=int]
                └── const: 1 [type=int]

# Insert value into hidden rowid column.
build
INSERT INTO abcde (a, rowid) VALUES (1, 2) RETURNING *
----
project
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int)
 └── insert abcde
      ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int) rowid:6(int!null)
      ├── insert-mapping:
      │    ├──  column1:7 => a:1
      │    ├──  column9:9 => b:2
      │    ├──  column10:10 => c:3
      │    ├──  column11:11 => d:4
      │    ├──  column1:7 => e:5
      │    └──  column2:8 => rowid:6
      └── project
           ├── columns: column11:11(int) column1:7(int) column2:8(int) column9:9(int) column10:10(int!null)
           ├── project
           │    ├── columns: column9:9(int) column10:10(int!null) column1:7(int) column2:8(int)
           │    ├── values
           │    │    ├── columns: column1:7(int) column2:8(int)
           │    │    └── tuple [type=tuple{int, int}]
           │    │         ├── const: 1 [type=int]
           │    │         └── const: 2 [type=int]
           │    └── projections
           │         ├── cast: INT8 [type=int]
           │         │    └── null [type=unknown]
           │         └── const: 10 [type=int]
           └── projections
                └── plus [type=int]
                     ├── plus [type=int]
                     │    ├── variable: column9 [type=int]
                     │    └── variable: column10 [type=int]
                     └── const: 1 [type=int]

# Use DEFAULT expressions in VALUES expression.
build
INSERT INTO abcde (c, b, a, rowid)
VALUES (DEFAULT, DEFAULT, 1, DEFAULT), (3, 2, 1, DEFAULT), (DEFAULT, DEFAULT, 2, 100)
RETURNING *, rowid
----
insert abcde
 ├── columns: a:1(int!null) b:2(int) c:3(int) d:4(int) e:5(int) rowid:6(int!null)
 ├── insert-mapping:
 │    ├──  column3:9 => a:1
 │    ├──  column2:8 => b:2
 │    ├──  column1:7 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column3:9 => e:5
 │    └──  column4:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column3:9(int) column4:10(int)
      ├── values
      │    ├── columns: column1:7(int) column2:8(int) column3:9(int) column4:10(int)
      │    ├── tuple [type=tuple{int, int, int, int}]
      │    │    ├── const: 10 [type=int]
      │    │    ├── cast: INT8 [type=int]
      │    │    │    └── null [type=unknown]
      │    │    ├── const: 1 [type=int]
      │    │    └── function: unique_rowid [type=int]
      │    ├── tuple [type=tuple{int, int, int, int}]
      │    │    ├── const: 3 [type=int]
      │    │    ├── const: 2 [type=int]
      │    │    ├── const: 1 [type=int]
      │    │    └── function: unique_rowid [type=int]
      │    └── tuple [type=tuple{int, int, int, int}]
      │         ├── const: 10 [type=int]
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 2 [type=int]
      │         └── const: 100 [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column2 [type=int]
                │    └── variable: column1 [type=int]
                └── const: 1 [type=int]

# Verify that there is no compile-time error when trying to insert a NULL
# DEFAULT value into a not-null column (it will fail at runtime).
build
INSERT INTO abcde (a) VALUES (DEFAULT)
----
insert abcde
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:7 => a:1
 │    ├──  column8:8 => b:2
 │    ├──  column9:9 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column1:7 => e:5
 │    └──  column10:10 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column8:8(int) column9:9(int!null) column10:10(int)
      ├── project
      │    ├── columns: column8:8(int) column9:9(int!null) column10:10(int) column1:7(int)
      │    ├── values
      │    │    ├── columns: column1:7(int)
      │    │    └── tuple [type=tuple{int}]
      │    │         └── cast: INT8 [type=int]
      │    │              └── null [type=unknown]
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         ├── const: 10 [type=int]
      │         └── function: unique_rowid [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column8 [type=int]
                │    └── variable: column9 [type=int]
                └── const: 1 [type=int]

# Mismatched type.
build
INSERT INTO xyz (x) VALUES (10)
----
error (42804): value type int doesn't match type STRING of column "x"

# Try to insert into computed column.
build
INSERT INTO abcde (a, b, c, d) VALUES (1, 2, 3, 4)
----
error (55000): cannot write directly to computed column "d"

# Try to insert DEFAULT expression into computed column.
build
INSERT INTO abcde (a, d) VALUES (1, DEFAULT)
----
error (55000): cannot write directly to computed column "d"

# Too many values.
build
INSERT INTO abcde (a, b) VALUES (1, 2, 3)
----
error (42601): INSERT has more expressions than target columns, 3 expressions for 2 targets

# Too few values.
build
INSERT INTO abcde (a, b) VALUES (1)
----
error (42601): INSERT has more target columns than expressions, 1 expressions for 2 targets

# Duplicate column name.
build
INSERT INTO abcde (a, b, a) VALUES (1, 2, 3)
----
error (42601): multiple assignments to the same column "a"

# Undefined column name.
build
INSERT INTO abcde (a, unk) VALUES (1, 2)
----
error (42703): column "unk" does not exist

# Return values from insert.
build
INSERT INTO abcde (b, a) SELECT x::int, y FROM xyz RETURNING *
----
project
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int)
 └── insert abcde
      ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int) rowid:6(int!null)
      ├── insert-mapping:
      │    ├──  y:8 => a:1
      │    ├──  x:10 => b:2
      │    ├──  column11:11 => c:3
      │    ├──  column13:13 => d:4
      │    ├──  y:8 => e:5
      │    └──  column12:12 => rowid:6
      └── project
           ├── columns: column13:13(int) y:8(int) x:10(int) column11:11(int!null) column12:12(int)
           ├── project
           │    ├── columns: column11:11(int!null) column12:12(int) y:8(int) x:10(int)
           │    ├── project
           │    │    ├── columns: x:10(int) y:8(int)
           │    │    ├── scan xyz
           │    │    │    └── columns: xyz.x:7(string!null) y:8(int) z:9(float)
           │    │    └── projections
           │    │         └── cast: INT8 [type=int]
           │    │              └── variable: xyz.x [type=string]
           │    └── projections
           │         ├── const: 10 [type=int]
           │         └── function: unique_rowid [type=int]
           └── projections
                └── plus [type=int]
                     ├── plus [type=int]
                     │    ├── variable: x [type=int]
                     │    └── variable: column11 [type=int]
                     └── const: 1 [type=int]

# Return hidden column.
build
INSERT INTO abcde (rowid, a) VALUES (1, 2) RETURNING *, rowid
----
insert abcde
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int) rowid:6(int!null)
 ├── insert-mapping:
 │    ├──  column2:8 => a:1
 │    ├──  column9:9 => b:2
 │    ├──  column10:10 => c:3
 │    ├──  column11:11 => d:4
 │    ├──  column2:8 => e:5
 │    └──  column1:7 => rowid:6
 └── project
      ├── columns: column11:11(int) column1:7(int) column2:8(int) column9:9(int) column10:10(int!null)
      ├── project
      │    ├── columns: column9:9(int) column10:10(int!null) column1:7(int) column2:8(int)
      │    ├── values
      │    │    ├── columns: column1:7(int) column2:8(int)
      │    │    └── tuple [type=tuple{int, int}]
      │    │         ├── const: 1 [type=int]
      │    │         └── const: 2 [type=int]
      │    └── projections
      │         ├── cast: INT8 [type=int]
      │         │    └── null [type=unknown]
      │         └── const: 10 [type=int]
      └── projections
           └── plus [type=int]
                ├── plus [type=int]
                │    ├── variable: column9 [type=int]
                │    └── variable: column10 [type=int]
                └── const: 1 [type=int]

# Use returning INSERT as a FROM expression.
build
SELECT * FROM [INSERT INTO abcde (a, b) SELECT y+1, y FROM xyz RETURNING *]
----
project
 ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int)
 └── insert abcde
      ├── columns: a:1(int!null) b:2(int) c:3(int!null) d:4(int) e:5(int) rowid:6(int!null)
      ├── insert-mapping:
      │    ├──  "?column?":10 => a:1
      │    ├──  y:8 => b:2
      │    ├──  column11:11 => c:3
      │    ├──  column13:13 => d:4
      │    ├──  "?column?":10 => e:5
      │    └──  column12:12 => rowid:6
      └── project
           ├── columns: column13:13(int) y:8(int) "?column?":10(int) column11:11(int!null) column12:12(int)
           ├── project
           │    ├── columns: column11:11(int!null) column12:12(int) y:8(int) "?column?":10(int)
           │    ├── project
           │    │    ├── columns: "?column?":10(int) y:8(int)
           │    │    ├── scan xyz
           │    │    │    └── columns: x:7(string!null) y:8(int) z:9(float)
           │    │    └── projections
           │    │         └── plus [type=int]
           │    │              ├── variable: y [type=int]
           │    │              └── const: 1 [type=int]
           │    └── projections
           │         ├── const: 10 [type=int]
           │         └── function: unique_rowid [type=int]
           └── projections
                └── plus [type=int]
                     ├── plus [type=int]
                     │    ├── variable: y [type=int]
                     │    └── variable: column11 [type=int]
                     └── const: 1 [type=int]

# ------------------------------------------------------------------------------
# Propagate desired INSERT types.
# ------------------------------------------------------------------------------

# Propagate types to VALUES.
build
INSERT INTO xyz VALUES ($1, $2 + 1, $3 + 1)
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:4 => x:1
 │    ├──  column2:5 => y:2
 │    └──  column3:6 => z:3
 └── values
      ├── columns: column1:4(string) column2:5(int) column3:6(float)
      └── tuple [type=tuple{string, int, float}]
           ├── placeholder: $1 [type=string]
           ├── plus [type=int]
           │    ├── placeholder: $2 [type=int]
           │    └── const: 1 [type=int]
           └── plus [type=float]
                ├── placeholder: $3 [type=float]
                └── const: 1.0 [type=float]

# Propagate types to VALUES (named columns).
build
INSERT INTO xyz (z, y, x) VALUES ($1 + 1, $2 + 1, $3)
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column3:6 => x:1
 │    ├──  column2:5 => y:2
 │    └──  column1:4 => z:3
 └── values
      ├── columns: column1:4(float) column2:5(int) column3:6(string)
      └── tuple [type=tuple{float, int, string}]
           ├── plus [type=float]
           │    ├── placeholder: $1 [type=float]
           │    └── const: 1.0 [type=float]
           ├── plus [type=int]
           │    ├── placeholder: $2 [type=int]
           │    └── const: 1 [type=int]
           └── placeholder: $3 [type=string]

# Propagate types to projection list.
build
INSERT INTO xyz ((SELECT $1, $2 + 1, $3 + 1))
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  "?column?":4 => x:1
 │    ├──  "?column?":5 => y:2
 │    └──  "?column?":6 => z:3
 └── project
      ├── columns: "?column?":4(string) "?column?":5(int) "?column?":6(float)
      ├── values
      │    └── tuple [type=tuple]
      └── projections
           ├── placeholder: $1 [type=string]
           ├── plus [type=int]
           │    ├── placeholder: $2 [type=int]
           │    └── const: 1 [type=int]
           └── plus [type=float]
                ├── placeholder: $3 [type=float]
                └── const: 1.0 [type=float]

# Propagate types to projection list (named columns).
build
INSERT INTO xyz (x, y, z) SELECT $1, $2 + 1, $3 + 1
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  "?column?":4 => x:1
 │    ├──  "?column?":5 => y:2
 │    └──  "?column?":6 => z:3
 └── project
      ├── columns: "?column?":4(string) "?column?":5(int) "?column?":6(float)
      ├── values
      │    └── tuple [type=tuple]
      └── projections
           ├── placeholder: $1 [type=string]
           ├── plus [type=int]
           │    ├── placeholder: $2 [type=int]
           │    └── const: 1 [type=int]
           └── plus [type=float]
                ├── placeholder: $3 [type=float]
                └── const: 1.0 [type=float]

# Propagate types to UNION.
build
INSERT INTO xyz (SELECT $1, $2 + 1, $3 + 1) UNION ALL (SELECT $1, $2 + 1, $3 + 1)
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  "?column?":10 => x:1
 │    ├──  "?column?":11 => y:2
 │    └──  "?column?":12 => z:3
 └── union-all
      ├── columns: "?column?":10(string) "?column?":11(int) "?column?":12(float)
      ├── left columns: "?column?":4(string) "?column?":5(int) "?column?":6(float)
      ├── right columns: "?column?":7(string) "?column?":8(int) "?column?":9(float)
      ├── project
      │    ├── columns: "?column?":4(string) "?column?":5(int) "?column?":6(float)
      │    ├── values
      │    │    └── tuple [type=tuple]
      │    └── projections
      │         ├── placeholder: $1 [type=string]
      │         ├── plus [type=int]
      │         │    ├── placeholder: $2 [type=int]
      │         │    └── const: 1 [type=int]
      │         └── plus [type=float]
      │              ├── placeholder: $3 [type=float]
      │              └── const: 1.0 [type=float]
      └── project
           ├── columns: "?column?":7(string) "?column?":8(int) "?column?":9(float)
           ├── values
           │    └── tuple [type=tuple]
           └── projections
                ├── placeholder: $1 [type=string]
                ├── plus [type=int]
                │    ├── placeholder: $2 [type=int]
                │    └── const: 1 [type=int]
                └── plus [type=float]
                     ├── placeholder: $3 [type=float]
                     └── const: 1.0 [type=float]

# Propagate types to UNION (named columns).
build
INSERT INTO xyz (x, z, y) SELECT $1, $2 + 1, $3 + 1 UNION ALL SELECT $1, $2 + 1, $3 + 1
----
insert xyz
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  "?column?":10 => x:1
 │    ├──  "?column?":12 => y:2
 │    └──  "?column?":11 => z:3
 └── union-all
      ├── columns: "?column?":10(string) "?column?":11(float) "?column?":12(int)
      ├── left columns: "?column?":4(string) "?column?":5(float) "?column?":6(int)
      ├── right columns: "?column?":7(string) "?column?":8(float) "?column?":9(int)
      ├── project
      │    ├── columns: "?column?":4(string) "?column?":5(float) "?column?":6(int)
      │    ├── values
      │    │    └── tuple [type=tuple]
      │    └── projections
      │         ├── placeholder: $1 [type=string]
      │         ├── plus [type=float]
      │         │    ├── placeholder: $2 [type=float]
      │         │    └── const: 1.0 [type=float]
      │         └── plus [type=int]
      │              ├── placeholder: $3 [type=int]
      │              └── const: 1 [type=int]
      └── project
           ├── columns: "?column?":7(string) "?column?":8(float) "?column?":9(int)
           ├── values
           │    └── tuple [type=tuple]
           └── projections
                ├── placeholder: $1 [type=string]
                ├── plus [type=float]
                │    ├── placeholder: $2 [type=float]
                │    └── const: 1.0 [type=float]
                └── plus [type=int]
                     ├── placeholder: $3 [type=int]
                     └── const: 1 [type=int]

# ------------------------------------------------------------------------------
# Tests with mutation columns.
# ------------------------------------------------------------------------------

# Test mutation columns with default and computed values.
build
INSERT INTO mutation (m, n) VALUES (1, 2)
----
insert mutation
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:6 => m:1
 │    ├──  column2:7 => n:2
 │    ├──  column8:8 => o:3
 │    └──  column9:9 => p:4
 ├── check columns: check1:10(bool)
 └── project
      ├── columns: check1:10(bool) column1:6(int) column2:7(int) column8:8(int!null) column9:9(int)
      ├── project
      │    ├── columns: column9:9(int) column1:6(int) column2:7(int) column8:8(int!null)
      │    ├── project
      │    │    ├── columns: column8:8(int!null) column1:6(int) column2:7(int)
      │    │    ├── values
      │    │    │    ├── columns: column1:6(int) column2:7(int)
      │    │    │    └── tuple [type=tuple{int, int}]
      │    │    │         ├── const: 1 [type=int]
      │    │    │         └── const: 2 [type=int]
      │    │    └── projections
      │    │         └── const: 10 [type=int]
      │    └── projections
      │         └── plus [type=int]
      │              ├── variable: column8 [type=int]
      │              └── variable: column2 [type=int]
      └── projections
           └── gt [type=bool]
                ├── variable: column1 [type=int]
                └── const: 0 [type=int]

# Use RETURNING clause and ensure that mutation columns aren't projected.
build
INSERT INTO mutation (m, n) VALUES (1, 2) RETURNING *
----
insert mutation
 ├── columns: m:1(int!null) n:2(int)
 ├── insert-mapping:
 │    ├──  column1:6 => m:1
 │    ├──  column2:7 => n:2
 │    ├──  column8:8 => o:3
 │    └──  column9:9 => p:4
 ├── check columns: check1:10(bool)
 └── project
      ├── columns: check1:10(bool) column1:6(int) column2:7(int) column8:8(int!null) column9:9(int)
      ├── project
      │    ├── columns: column9:9(int) column1:6(int) column2:7(int) column8:8(int!null)
      │    ├── project
      │    │    ├── columns: column8:8(int!null) column1:6(int) column2:7(int)
      │    │    ├── values
      │    │    │    ├── columns: column1:6(int) column2:7(int)
      │    │    │    └── tuple [type=tuple{int, int}]
      │    │    │         ├── const: 1 [type=int]
      │    │    │         └── const: 2 [type=int]
      │    │    └── projections
      │    │         └── const: 10 [type=int]
      │    └── projections
      │         └── plus [type=int]
      │              ├── variable: column8 [type=int]
      │              └── variable: column2 [type=int]
      └── projections
           └── gt [type=bool]
                ├── variable: column1 [type=int]
                └── const: 0 [type=int]

# Try to reference write-only mutation column in RETURNING clause.
build
INSERT INTO mutation (m, n) VALUES (1, 2) RETURNING o
----
error (42703): column "o" does not exist

# Try to reference delete-only mutation column in RETURNING clause.
build
INSERT INTO mutation (m, n) VALUES (1, 2) RETURNING p
----
error (42703): column "p" does not exist

# Try to insert into mutation column.
build
INSERT INTO mutation (m, n, p) VALUES (1, 2, 3)
----
error (42703): column "p" does not exist

# ------------------------------------------------------------------------------
# Test check constraints.
# ------------------------------------------------------------------------------

# Insert constants.
build
INSERT INTO checks (a, b, c) VALUES (1, 2, 3)
----
insert checks
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  column1:5 => a:1
 │    ├──  column2:6 => b:2
 │    ├──  column3:7 => c:3
 │    └──  column8:8 => d:4
 ├── check columns: check1:9(bool) check2:10(bool)
 └── project
      ├── columns: check1:9(bool) check2:10(bool) column1:5(int) column2:6(int) column3:7(int) column8:8(int)
      ├── project
      │    ├── columns: column8:8(int) column1:5(int) column2:6(int) column3:7(int)
      │    ├── values
      │    │    ├── columns: column1:5(int) column2:6(int) column3:7(int)
      │    │    └── tuple [type=tuple{int, int, int}]
      │    │         ├── const: 1 [type=int]
      │    │         ├── const: 2 [type=int]
      │    │         └── const: 3 [type=int]
      │    └── projections
      │         └── plus [type=int]
      │              ├── variable: column3 [type=int]
      │              └── const: 1 [type=int]
      └── projections
           ├── lt [type=bool]
           │    ├── variable: column2 [type=int]
           │    └── variable: column8 [type=int]
           └── gt [type=bool]
                ├── variable: column1 [type=int]
                └── const: 0 [type=int]

# Insert results of SELECT.
build
INSERT INTO checks SELECT a, b, c FROM abcde
----
insert checks
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  abcde.a:5 => checks.a:1
 │    ├──  abcde.b:6 => checks.b:2
 │    ├──  abcde.c:7 => checks.c:3
 │    └──  column11:11 => checks.d:4
 ├── check columns: check1:12(bool) check2:13(bool)
 └── project
      ├── columns: check1:12(bool) check2:13(bool) abcde.a:5(int!null) abcde.b:6(int) abcde.c:7(int) column11:11(int)
      ├── project
      │    ├── columns: column11:11(int) abcde.a:5(int!null) abcde.b:6(int) abcde.c:7(int)
      │    ├── project
      │    │    ├── columns: abcde.a:5(int!null) abcde.b:6(int) abcde.c:7(int)
      │    │    └── scan abcde
      │    │         └── columns: abcde.a:5(int!null) abcde.b:6(int) abcde.c:7(int) abcde.d:8(int) e:9(int) rowid:10(int!null)
      │    └── projections
      │         └── plus [type=int]
      │              ├── variable: abcde.c [type=int]
      │              └── const: 1 [type=int]
      └── projections
           ├── lt [type=bool]
           │    ├── variable: abcde.b [type=int]
           │    └── variable: column11 [type=int]
           └── gt [type=bool]
                ├── variable: abcde.a [type=int]
                └── const: 0 [type=int]

# ------------------------------------------------------------------------------
# Test decimal column rounding.
# ------------------------------------------------------------------------------

opt
INSERT INTO decimals (a, b) VALUES (1.1, ARRAY[0.95, NULL, 15])
----
insert decimals
 ├── columns: <none>
 ├── insert-mapping:
 │    ├──  a:8 => decimals.a:1
 │    ├──  b:9 => decimals.b:2
 │    ├──  c:10 => decimals.c:3
 │    └──  d:12 => decimals.d:4
 ├── check columns: check1:13(bool) check2:14(bool)
 └── project
      ├── columns: check1:13(bool) check2:14(bool) d:12(decimal) a:8(decimal) b:9(decimal[]) c:10(decimal)
      ├── values
      │    ├── columns: a:8(decimal) b:9(decimal[]) c:10(decimal)
      │    └── tuple [type=tuple{decimal, decimal[], decimal}]
      │         ├── function: crdb_internal.round_decimal_values [type=decimal]
      │         │    ├── const: 1.1 [type=decimal]
      │         │    └── const: 0 [type=int]
      │         ├── function: crdb_internal.round_decimal_values [type=decimal[]]
      │         │    ├── const: ARRAY[0.95,NULL,15] [type=decimal[]]
      │         │    └── const: 1 [type=int]
      │         └── function: crdb_internal.round_decimal_values [type=decimal]
      │              ├── const: 1.23 [type=decimal]
      │              └── const: 1 [type=int]
      └── projections
           ├── eq [type=bool]
           │    ├── variable: a [type=decimal]
           │    └── function: round [type=decimal]
           │         └── variable: a [type=decimal]
           ├── gt [type=bool]
           │    ├── indirection [type=decimal]
           │    │    ├── variable: b [type=decimal[]]
           │    │    └── const: 0 [type=int]
           │    └── const: 1 [type=decimal]
           └── function: crdb_internal.round_decimal_values [type=decimal]
                ├── plus [type=decimal]
                │    ├── variable: a [type=decimal]
                │    └── variable: c [type=decimal]
                └── const: 1 [type=int]
