File: drop_column_in_struct.test

package info (click to toggle)
duckdb 1.5.1-2
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 299,196 kB
  • sloc: cpp: 865,414; ansic: 57,292; python: 18,871; sql: 12,663; lisp: 11,751; yacc: 7,412; lex: 1,682; sh: 747; makefile: 558
file content (98 lines) | stat: -rw-r--r-- 1,691 bytes parent folder | download | duplicates (4)
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/drop_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 drop 'key' from the map
statement error
ALTER TABLE test DROP COLUMN s.key
----
Catalog Error: Cannot drop field 'key' from column 's' - it's not a struct

# attempt to drop 'value' from the map
statement error
ALTER TABLE test DROP COLUMN s.value
----
Catalog Error: Cannot drop field 'value' from column 's' - it's not a struct


# drop a column from the struct inside the 'value'
statement ok
ALTER TABLE test DROP COLUMN s.value.j

query I
select * from test;
----
{{'n': 3, 'm': 3}={'i': 1}}
{{'n': 4, 'm': 4}={'i': 2}}

# drop a column from the struct inside the 'key'
statement ok
ALTER TABLE test DROP COLUMN s.key.n

query I
select * from test;
----
{{'m': 3}={'i': 1}}
{{'m': 4}={'i': 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)}))

# drop a column from the struct in the 'key'
statement ok
ALTER TABLE test DROP COLUMN s.a.key.m

query I
select * from test;
----
{'a': {{'n': 3}={'i': 1, 'j': 1}}}
{'a': {{'n': 4}={'i': 2, 'j': 2}}}

# drop a column from the struct in the 'value'
statement ok
ALTER TABLE test DROP COLUMN s.a.value.j

query I
select * from test;
----
{'a': {{'n': 3}={'i': 1}}}
{'a': {{'n': 4}={'i': 2}}}