1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
# name: test/sql/alter/map/rename_column_in_struct.test
# group: [map]
statement ok
CREATE TABLE test(
s MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
statement ok
INSERT INTO test VALUES
(MAP {ROW(3,3): ROW(1, 1)}),
(MAP {ROW(4,4): ROW(2, 2)})
# attempt to rename 'key'
statement error
ALTER TABLE test RENAME COLUMN s.key to anything
----
Catalog Error: Cannot rename field 'key' from column 's' - can only rename fields inside a struct
# attempt to rename 'value'
statement error
ALTER TABLE test RENAME COLUMN s.value to anything
----
Catalog Error: Cannot rename field 'value' from column 's' - can only rename fields inside a struct
# rename a column from the struct inside the 'value'
statement ok
ALTER TABLE test RENAME COLUMN s.value.j TO abc
query I
select * from test;
----
{{'n': 3, 'm': 3}={'i': 1, 'abc': 1}}
{{'n': 4, 'm': 4}={'i': 2, 'abc': 2}}
# rename a column from the struct inside the 'key'
statement ok
ALTER TABLE test RENAME COLUMN s.key.n TO def
query I
select * from test;
----
{{'def': 3, 'm': 3}={'i': 1, 'abc': 1}}
{{'def': 4, 'm': 4}={'i': 2, 'abc': 2}}
statement ok
drop table test;
statement ok
CREATE TABLE test(
s STRUCT(
a MAP(
STRUCT(
n INTEGER,
m INTEGER
),
STRUCT(
i INTEGER,
j INTEGER
)
)
)
)
statement ok
INSERT INTO test VALUES
(ROW(MAP {ROW(3,3): ROW(1, 1)})),
(ROW(MAP {ROW(4,4): ROW(2, 2)}))
# rename a column from the struct in the 'key'
statement ok
ALTER TABLE test RENAME COLUMN s.a.key.m TO abc
query I
select * from test;
----
{'a': {{'n': 3, 'abc': 3}={'i': 1, 'j': 1}}}
{'a': {{'n': 4, 'abc': 4}={'i': 2, 'j': 2}}}
# rename a column from the struct in the 'value'
statement ok
ALTER TABLE test RENAME COLUMN s.a.value.j TO def
query I
select * from test;
----
{'a': {{'n': 3, 'abc': 3}={'i': 1, 'def': 1}}}
{'a': {{'n': 4, 'abc': 4}={'i': 2, 'def': 2}}}
|