should be it

This commit is contained in:
2025-10-24 19:21:19 -05:00
parent a4b23fc57c
commit f09560c7b1
14047 changed files with 3161551 additions and 1 deletions

View File

@@ -0,0 +1,67 @@
# name: test/sql/alter/list/add_column_in_struct.test
# description: Test adding fields to a STRUCT.
# group: [list]
query I
WITH cte AS (
SELECT a::STRUCT(i INTEGER, j INTEGER)[] a FROM
VALUES ([ROW(1, 1)]), ([ROW(2, 2)]) t(a)
)
SELECT remap_struct(
a,
NULL::STRUCT(i INTEGER, j INTEGER, k INTEGER)[],
{'list': ('list', {'i': 'i', 'j': 'j'})},
{'list': {'k': NULL::INTEGER}}
) FROM cte;
----
[{'i': 1, 'j': 1, 'k': NULL}]
[{'i': 2, 'j': 2, 'k': NULL}]
statement ok
CREATE TABLE test(s STRUCT(i INTEGER, j INTEGER)[])
statement ok
INSERT INTO test VALUES ([ROW(1, 1)]), ([ROW(2, 2)])
# Add a field to a STRUCT.
statement ok
ALTER TABLE test ADD COLUMN s.element.k INTEGER
query I
SELECT * FROM test;
----
[{'i': 1, 'j': 1, 'k': NULL}]
[{'i': 2, 'j': 2, 'k': NULL}]
statement ok
DROP TABLE test;
statement ok
CREATE TABLE test(
s STRUCT(
a STRUCT(i INTEGER, j INTEGER)[]
)
)
statement ok
INSERT INTO test VALUES (ROW([ROW(1, 1)])), (ROW([ROW(2, 2)]))
# Add another (one more nesting level) STRUCT field.
statement ok
ALTER TABLE test ADD COLUMN s.a.element.k INTEGER
query I
SELECT * FROM test;
----
{'a': [{'i': 1, 'j': 1, 'k': NULL}]}
{'a': [{'i': 2, 'j': 2, 'k': NULL}]}
# Try to add an element to the list.
statement error
ALTER TABLE test ADD COLUMN s.a.not_element INTEGER
----
<REGEX>:Binder Error.*Column a is not a struct - ALTER TABLE can only add fields to structs.*

View File

@@ -0,0 +1,51 @@
# name: test/sql/alter/list/drop_column_in_struct.test
# description: Test dropping fields in a STRUCT.
# group: [list]
statement ok
CREATE TABLE test(s STRUCT(i INTEGER, j INTEGER)[])
statement ok
INSERT INTO test VALUES ([ROW(1, 1)]), ([ROW(2, 2)])
# Try to drop element from the list.
statement error
ALTER TABLE test DROP COLUMN s.element
----
<REGEX>:Catalog Error.*Cannot drop field.*not a struct.*
# Now drop a STRUCT field.
statement ok
ALTER TABLE test DROP COLUMN s.element.j
query I
SELECT * FROM test
----
[{'i': 1}]
[{'i': 2}]
statement ok
DROP TABLE test;
statement ok
CREATE TABLE test(
s STRUCT(
a STRUCT(i INTEGER, j INTEGER)[]
)
)
statement ok
INSERT INTO test VALUES (ROW([ROW(1, 1)])), (ROW([ROW(2, 2)]))
# Drop another (one more nesting level) STRUCT field.
statement ok
ALTER TABLE test DROP COLUMN s.a.element.i
query I
SELECT * FROM test
----
{'a': [{'j': 1}]}
{'a': [{'j': 2}]}

View File

@@ -0,0 +1,58 @@
# name: test/sql/alter/list/rename_column_in_struct.test
# group: [list]
statement ok
CREATE TABLE test(
s STRUCT(
i INTEGER,
j INTEGER
)[]
)
statement ok
INSERT INTO test VALUES
([ROW(1, 1)]),
([ROW(2, 2)])
# attempt to rename 'element' from the list
statement error
ALTER TABLE test RENAME COLUMN s.element TO not_element
----
Catalog Error: Cannot rename field 'element' from column 's' - can only rename fields inside a struct
statement ok
ALTER TABLE test RENAME COLUMN s.element.j TO k
query I
select * from test
----
[{'i': 1, 'k': 1}]
[{'i': 2, 'k': 2}]
statement ok
drop table test;
statement ok
CREATE TABLE test(
s STRUCT(
a STRUCT(
i INTEGER,
j INTEGER
)[]
)
)
statement ok
INSERT INTO test VALUES
(ROW([ROW(1, 1)])),
(ROW([ROW(2, 2)]))
# add a column to a struct
statement ok
ALTER TABLE test RENAME COLUMN s.a.element.i TO k
query I
select * from test
----
{'a': [{'k': 1, 'j': 1}]}
{'a': [{'k': 2, 'j': 2}]}