should be it
This commit is contained in:
19
external/duckdb/test/sql/alter/drop_col/test_drop_col.test
vendored
Normal file
19
external/duckdb/test/sql/alter/drop_col/test_drop_col.test
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: standard drop column
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
|
||||
49
external/duckdb/test/sql/alter/drop_col/test_drop_col_check.test
vendored
Normal file
49
external/duckdb/test/sql/alter/drop_col/test_drop_col_check.test
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_check.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN with check constraint
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER CHECK(j < 10))
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
query II
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (3)
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test2(i INTEGER, j INTEGER CHECK(i+j < 10))
|
||||
|
||||
statement ok
|
||||
INSERT INTO test2 VALUES (1, 1), (2, 2)
|
||||
|
||||
query II
|
||||
SELECT * FROM test2
|
||||
----
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
|
||||
statement error
|
||||
ALTER TABLE test2 DROP COLUMN j
|
||||
----
|
||||
Catalog Error: Cannot drop column "j"
|
||||
35
external/duckdb/test/sql/alter/drop_col/test_drop_col_check_next.test
vendored
Normal file
35
external/duckdb/test/sql/alter/drop_col/test_drop_col_check_next.test
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_check_next.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN with check constraint on subsequent column
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER CHECK(j < 10))
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
query II
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
|
||||
statement error
|
||||
INSERT INTO test VALUES (20)
|
||||
----
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (3)
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
28
external/duckdb/test/sql/alter/drop_col/test_drop_col_failure.test
vendored
Normal file
28
external/duckdb/test/sql/alter/drop_col/test_drop_col_failure.test
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_failure.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: Incorrect DROP COLUMN usage
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# cannot drop column which does not exist
|
||||
statement error
|
||||
ALTER TABLE test DROP COLUMN blabla
|
||||
----
|
||||
Binder Error: Table "test" does not have a column with name "blabla"
|
||||
|
||||
# unless IF EXISTS is specified
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN IF EXISTS blabla
|
||||
|
||||
# cannot drop ALL columns of a table
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
|
||||
statement error
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
----
|
||||
Catalog Error: Cannot drop column: table only has one column remaining
|
||||
24
external/duckdb/test/sql/alter/drop_col/test_drop_col_index.test
vendored
Normal file
24
external/duckdb/test/sql/alter/drop_col/test_drop_col_index.test
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_index.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN with index built on subsequent column
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
statement ok
|
||||
CREATE INDEX i_index ON test(j)
|
||||
|
||||
# cannot drop indexed column
|
||||
statement error
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
----
|
||||
Catalog Error: Cannot drop this column: an index depends on it
|
||||
|
||||
# we also cannot drop the column i (for now) because an index depends on a subsequent column
|
||||
statement error
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
----
|
||||
Catalog Error: Cannot drop this column: an index depends on a column
|
||||
31
external/duckdb/test/sql/alter/drop_col/test_drop_col_not_null.test
vendored
Normal file
31
external/duckdb/test/sql/alter/drop_col/test_drop_col_not_null.test
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_not_null.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN with NOT NULL constraint
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER NOT NULL)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
query II
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (3)
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
40
external/duckdb/test/sql/alter/drop_col/test_drop_col_not_null_next.test
vendored
Normal file
40
external/duckdb/test/sql/alter/drop_col/test_drop_col_not_null_next.test
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_not_null_next.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN with NOT NULL constraint on subsequent column
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER, k INTEGER NOT NULL)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1, 11), (2, 2, 12)
|
||||
|
||||
query III
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
1
|
||||
11
|
||||
2
|
||||
2
|
||||
12
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
statement error
|
||||
INSERT INTO test VALUES (3, NULL)
|
||||
----
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (3, 13)
|
||||
|
||||
query II
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
11
|
||||
2
|
||||
12
|
||||
3
|
||||
13
|
||||
|
||||
28
external/duckdb/test/sql/alter/drop_col/test_drop_col_operations.test
vendored
Normal file
28
external/duckdb/test/sql/alter/drop_col/test_drop_col_operations.test
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_operations.test
|
||||
# description: Test various operations on a table after dropping a column
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test SELECT i, i FROM range(100) tbl(i);
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
|
||||
statement ok
|
||||
DELETE FROM test WHERE j%2=0
|
||||
|
||||
query II
|
||||
SELECT COUNT(j), SUM(j) FROM test
|
||||
----
|
||||
50 2500
|
||||
|
||||
statement ok
|
||||
UPDATE test SET j=j+100
|
||||
|
||||
query II
|
||||
SELECT COUNT(j), SUM(j) FROM test
|
||||
----
|
||||
50 7500
|
||||
29
external/duckdb/test/sql/alter/drop_col/test_drop_col_pk.test
vendored
Normal file
29
external/duckdb/test/sql/alter/drop_col/test_drop_col_pk.test
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_pk.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: DROP COLUMN from table with primary key constraint
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER PRIMARY KEY, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# cannot drop primary key column
|
||||
statement error
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
----
|
||||
|
||||
# but we can drop column "j"
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (3)
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
3
|
||||
|
||||
33
external/duckdb/test/sql/alter/drop_col/test_drop_col_rollback.test
vendored
Normal file
33
external/duckdb/test/sql/alter/drop_col/test_drop_col_rollback.test
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_rollback.test
|
||||
# description: Test ALTER TABLE DROP COLUMN: Rollback of DROP COLUMN
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
statement ok
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
query I
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
|
||||
statement ok
|
||||
ROLLBACK
|
||||
|
||||
query II
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
1
|
||||
2
|
||||
2
|
||||
|
||||
144
external/duckdb/test/sql/alter/drop_col/test_drop_col_transactions.test
vendored
Normal file
144
external/duckdb/test/sql/alter/drop_col/test_drop_col_transactions.test
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_transactions.test
|
||||
# description: Test ALTER TABLE DROP COLUMN with multiple transactions
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok con1
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# Only one pending table alter can be active at a time
|
||||
statement ok con1
|
||||
BEGIN TRANSACTION
|
||||
|
||||
# con removes a column to test
|
||||
statement ok con1
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
# con2 cannot add a new column now!
|
||||
statement error con2
|
||||
ALTER TABLE test ADD COLUMN k INTEGER
|
||||
----
|
||||
TransactionContext Error: Catalog write-write conflict
|
||||
|
||||
statement ok con1
|
||||
COMMIT
|
||||
|
||||
# we can add the column after the commit
|
||||
statement ok con2
|
||||
ALTER TABLE test ADD COLUMN k INTEGER
|
||||
|
||||
statement ok con1
|
||||
DROP TABLE test
|
||||
|
||||
statement ok con1
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# Can only append to newest table
|
||||
statement ok con1
|
||||
BEGIN TRANSACTION
|
||||
|
||||
# con removes a column from test
|
||||
statement ok con1
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
|
||||
# con2 cannot append now!
|
||||
statement error con2
|
||||
INSERT INTO test (i, j) VALUES (3, 3)
|
||||
----
|
||||
<REGEX>:.*TransactionContext Error: Transaction conflict.*altered by a different transaction.*
|
||||
|
||||
# nor delete
|
||||
statement error con2
|
||||
DELETE FROM test WHERE i=1
|
||||
----
|
||||
<REGEX>:.*TransactionContext Error: Failed to commit.*another transaction has altered this table.*
|
||||
|
||||
query I con1
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
|
||||
query II con2
|
||||
SELECT * FROM test
|
||||
----
|
||||
1 1
|
||||
2 2
|
||||
|
||||
# we can't update on tables that have been altered
|
||||
statement error con2
|
||||
UPDATE test SET j=100
|
||||
----
|
||||
<REGEX>:.*TransactionContext Error: Transaction conflict.*altered by a different transaction.*
|
||||
|
||||
query I con1
|
||||
SELECT * FROM test
|
||||
----
|
||||
1
|
||||
2
|
||||
|
||||
statement ok con1
|
||||
UPDATE test SET j=100
|
||||
|
||||
statement ok con1
|
||||
COMMIT
|
||||
|
||||
query I con1
|
||||
SELECT * FROM test
|
||||
----
|
||||
100
|
||||
100
|
||||
|
||||
statement ok con1
|
||||
DROP TABLE test
|
||||
|
||||
statement ok con1
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# Alter table while other transaction still has pending appends
|
||||
statement ok con2
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok con2
|
||||
INSERT INTO test VALUES (3, 3)
|
||||
|
||||
# now con adds a column
|
||||
statement ok con1
|
||||
ALTER TABLE test DROP COLUMN i
|
||||
|
||||
# cannot commit con2! conflict on append
|
||||
statement error con2
|
||||
COMMIT
|
||||
----
|
||||
<REGEX>:.*TransactionContext Error: Failed to commit.*altered by a different transaction.*
|
||||
|
||||
statement ok con1
|
||||
DROP TABLE test
|
||||
|
||||
statement ok con1
|
||||
CREATE TABLE test(i INTEGER, j INTEGER)
|
||||
|
||||
statement ok con1
|
||||
INSERT INTO test VALUES (1, 1), (2, 2)
|
||||
|
||||
# Create index on column that has been removed by other transaction
|
||||
# con2 removes a column
|
||||
statement ok con2
|
||||
BEGIN TRANSACTION
|
||||
|
||||
statement ok con2
|
||||
ALTER TABLE test DROP COLUMN j
|
||||
|
||||
# now con tries to add an index to that column: this should fail
|
||||
statement error con1
|
||||
CREATE INDEX i_index ON test(j)
|
||||
----
|
||||
<REGEX>:.*TransactionContext Error: Transaction conflict: cannot add an index.*
|
||||
18
external/duckdb/test/sql/alter/drop_col/test_drop_col_with_generated_cols.test
vendored
Normal file
18
external/duckdb/test/sql/alter/drop_col/test_drop_col_with_generated_cols.test
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
# name: test/sql/alter/drop_col/test_drop_col_with_generated_cols.test
|
||||
# description: Test ALTER TABLE DROP COLUMN with generated cols in the table
|
||||
# group: [drop_col]
|
||||
|
||||
statement ok
|
||||
create table t(i int, j as (2), k int, m as (3), n int);
|
||||
|
||||
statement ok
|
||||
alter table t drop column n;
|
||||
|
||||
statement ok
|
||||
alter table t drop column m;
|
||||
|
||||
statement ok
|
||||
alter table t drop column k;
|
||||
|
||||
statement ok
|
||||
alter table t drop column j;
|
||||
Reference in New Issue
Block a user