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,27 @@
# name: test/sql/alter/rename_table/test_rename_bug4455_schema.test
# description: Test ALTER TABLE RENAME COLUMN
# group: [rename_table]
statement ok
create schema public;
statement ok
set schema=public;
statement ok
create table a1 (c int);
statement ok
alter table public.a1 rename to a2;
statement ok
alter table a2 rename to a3;
statement ok
create view v1 as select 42;
statement ok
alter view public.v1 rename to v2;
statement ok
alter view v2 rename to v3;

View File

@@ -0,0 +1,127 @@
# name: test/sql/alter/rename_table/test_rename_table.test
# description: Test RENAME TABLE single transaction
# group: [rename_table]
statement ok
CREATE TABLE tbl(i INTEGER);
statement ok
INSERT INTO tbl VALUES (999), (100);
statement ok
BEGIN TRANSACTION
statement ok
ALTER TABLE tbl RENAME TO tbl2
query I
SELECT * FROM tbl2
----
999
100
statement error
SELECT * FROM tbl
----
statement ok
ROLLBACK
query I
SELECT * FROM tbl;
----
999
100
statement error
SELECT * FROM tbl2
----
statement ok
BEGIN TRANSACTION;
statement ok
ALTER TABLE tbl RENAME TO tbl2
statement ok
COMMIT
query I
SELECT * FROM tbl2
----
999
100
statement error
SELECT * FROM tbl
----
query I
SELECT * FROM tbl2
----
999
100
# multiple renames in the same transaction
statement ok
BEGIN TRANSACTION
statement ok
ALTER TABLE tbl2 RENAME TO tbl3
statement ok
ALTER TABLE tbl3 RENAME TO tbl4
statement ok
ALTER TABLE tbl4 RENAME TO tbl5
statement ok
ROLLBACK
# everything was rolled back
query I
SELECT * FROM tbl2
----
999
100
statement error
SELECT * FROM tbl5
----
statement ok
BEGIN TRANSACTION
statement ok
ALTER TABLE tbl2 RENAME TO tbl3
statement ok
ALTER TABLE tbl3 RENAME TO tbl4
statement ok
ALTER TABLE tbl4 RENAME TO tbl5
statement ok
COMMIT
# everything was committed
statement error
SELECT * FROM tbl2
----
query I
SELECT * FROM tbl5
----
999
100
# we can create these tables again
statement ok
CREATE TABLE tbl2(i INTEGER);
statement ok
CREATE TABLE tbl3(i INTEGER);
statement ok
CREATE TABLE tbl4(i INTEGER);

View File

@@ -0,0 +1,22 @@
# name: test/sql/alter/rename_table/test_rename_table_case.test
# description: Test RENAME TABLE only changing the case
# group: [rename_table]
statement ok
create table MY_TABLE (i integer);
statement ok
insert into MY_TABLE values(42);
statement ok
alter table MY_TABLE rename to my_table;
query I
select * from my_table;
----
42
query I
select * from MY_TABLE;
----
42

View File

@@ -0,0 +1,81 @@
# name: test/sql/alter/rename_table/test_rename_table_chain_commit.test
# description: test a chain of table creates and renames in a transaction, followed by a commit
# group: [rename_table]
statement ok con1
CREATE TABLE entry(i INTEGER);
statement ok con1
INSERT INTO entry VALUES (1)
query I con2
SELECT * FROM entry
----
1
statement ok con1
BEGIN TRANSACTION;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
statement ok con1
CREATE TABLE entry(j INTEGER);
statement ok con1
INSERT INTO entry VALUES (2)
statement ok con1
ALTER TABLE entry2 RENAME TO entry3;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
statement ok con1
CREATE TABLE entry(k INTEGER);
statement ok con1
ALTER TABLE entry3 RENAME TO entry4;
statement ok con1
ALTER TABLE entry2 RENAME TO entry3;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
query I con2
SELECT * FROM entry
----
1
statement error con2
SELECT * FROM entry2
----
statement error con2
SELECT * FROM entry3
----
statement error con2
SELECT * FROM entry4
----
statement ok con1
COMMIT
statement error con2
SELECT * FROM entry
----
query I con2
SELECT * FROM entry4
----
1
query I con2
SELECT * FROM entry3
----
2
statement ok con2
SELECT * FROM entry2

View File

@@ -0,0 +1,74 @@
# name: test/sql/alter/rename_table/test_rename_table_chain_rollback.test
# description: test a chain of table creates and renames in a transaction, followed by a rollback
# group: [rename_table]
statement ok con1
CREATE TABLE entry(i INTEGER);
statement ok con1
INSERT INTO entry VALUES (1)
query I con2
SELECT * FROM entry
----
1
statement ok con1
BEGIN TRANSACTION;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
statement ok con1
CREATE TABLE entry(i INTEGER);
statement ok con1
ALTER TABLE entry2 RENAME TO entry3;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
statement ok con1
CREATE TABLE entry(i INTEGER);
statement ok con1
ALTER TABLE entry3 RENAME TO entry4;
statement ok con1
ALTER TABLE entry2 RENAME TO entry3;
statement ok con1
ALTER TABLE entry RENAME TO entry2;
query I con2
SELECT * FROM entry
----
1
statement error con2
SELECT * FROM entry2
----
Catalog Error: Table with name entry2 does not exist
statement error con2
SELECT * FROM entry3
----
Catalog Error: Table with name entry3 does not exist
statement error con2
SELECT * FROM entry4
----
Catalog Error: Table with name entry4 does not exist
statement ok con1
ROLLBACK
query I con2
SELECT * FROM entry
----
1
statement error con2
SELECT * FROM entry4
----
Catalog Error: Table with name entry4 does not exist

View File

@@ -0,0 +1,201 @@
# name: test/sql/alter/rename_table/test_rename_table_collision.test
# description: Test RENAME TABLE multiple transactions with rename after drop
# group: [rename_table]
statement ok con1
CREATE TABLE t1(i INTEGER);
statement ok con1
INSERT INTO t1 VALUES (1), (2), (3);
statement ok con2
CREATE TABLE t2(i VARCHAR);
statement ok con2
INSERT INTO t2 VALUES (4), (5), (6);
statement ok con2
BEGIN TRANSACTION
statement ok con2
DROP TABLE t2;
statement ok con2
ALTER TABLE t1 RENAME TO t2;
query I con2
SELECT i FROM t2 ORDER BY i;
----
1
2
3
query I con1
SELECT i FROM t1 ORDER BY i;
----
1
2
3
query I con1
SELECT i FROM t2 ORDER BY i;
----
4
5
6
statement ok con2
COMMIT
query I con1
SELECT i FROM t2 ORDER BY i;
----
1
2
3
statement error con1
SELECT * FROM t1
----
# Now we're going to do a rollback instead of a commit
statement ok con2
BEGIN TRANSACTION
statement ok con2
ALTER TABLE t2 RENAME TO t3;
statement error con1
SELECT i FROM t3 ORDER BY i
----
statement error con2
SELECT i FROM t2 ORDER BY i
----
query I con2
SELECT i FROM t3 ORDER BY i
----
1
2
3
statement ok con2
DROP TABLE t3;
query I con1
SELECT i FROM t2 ORDER BY i;
----
1
2
3
statement ok con2
CREATE TABLE t2 (i integer)
statement ok con2
INSERT INTO t2 VALUES (7), (8), (9)
query I con2
SELECT i FROM t2 ORDER BY i
----
7
8
9
statement ok con2
ROLLBACK
query I con1
SELECT i FROM t2 ORDER BY i;
----
1
2
3
query I con2
SELECT i FROM t2 ORDER BY i;
----
1
2
3
# alter/create collision
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
ALTER TABLE t2 RENAME TO t3
statement error con2
CREATE TABLE t3 (i INTEGER)
----
statement ok con1
ROLLBACK
statement ok con2
ROLLBACK
# alter/alter collision
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con2
ALTER TABLE t2 RENAME TO t3
statement error con1
ALTER TABLE t2 RENAME TO t4
----
statement ok con1
ROLLBACK
statement ok con2
ROLLBACK
# create some additional reference tables
# for testing, outside of any transaction
statement ok con1
CREATE TABLE e1 (i INTEGER)
statement ok con2
CREATE TABLE e2 (i INTEGER)
# crossing drops/renames
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
DROP TABLE e2
statement ok con2
DROP TABLE e1
statement error con1
ALTER TABLE e1 RENAME TO e2
----
statement error con2
ALTER TABLE e2 RENAME TO e1
----
statement ok con1
ROLLBACK
statement ok con2
ROLLBACK

View File

@@ -0,0 +1,53 @@
# name: test/sql/alter/rename_table/test_rename_table_constraints.test
# description: Test RENAME TABLE with constraints
# group: [rename_table]
# create a table with a check constraint
statement ok
CREATE TABLE tbl(i INTEGER PRIMARY KEY, j INTEGER CHECK(j < 10))
# check primary key constrain
statement ok
INSERT INTO tbl VALUES (999, 4), (1000, 5)
statement error
INSERT INTO tbl VALUES (999, 4), (1000, 5)
----
# check value constrain (j < 10)
statement ok
INSERT INTO tbl VALUES (9999, 0), (10000, 1)
statement error
INSERT INTO tbl VALUES (777, 10), (888, 10)
----
query II
SELECT * FROM tbl
----
999 4
1000 5
9999 0
10000 1
statement ok
ALTER TABLE tbl RENAME TO new_tbl
# insert two conflicting pairs at the same time
statement error
INSERT INTO new_tbl VALUES (999, 0), (1000, 1)
----
# insert two conflicting pairs at the same time
statement error
INSERT INTO new_tbl VALUES (9999, 0), (10000, 1)
----
# insert values out of range constrain
statement error
INSERT INTO new_tbl VALUES (1, 10), (2, 999)
----
statement ok
INSERT INTO new_tbl VALUES (66, 6), (55, 5)

View File

@@ -0,0 +1,21 @@
# name: test/sql/alter/rename_table/test_rename_table_incorrect.test
# description: Test RENAME TABLE: table does not exist and rename to an already existing table
# group: [rename_table]
statement ok
CREATE TABLE tbl(i INTEGER)
statement ok
CREATE TABLE tbl2(i INTEGER)
# Renaming a non existing table
statement error
ALTER TABLE non_table RENAME TO tbl
----
Catalog Error: Table with name non_table does not exist
# rename to an already existing table
statement error
ALTER TABLE tbl2 RENAME TO tbl
----
Catalog Error: Could not rename "tbl2" to "tbl"

View File

@@ -0,0 +1,113 @@
# name: test/sql/alter/rename_table/test_rename_table_many_transactions.test
# description: Test RENAME TABLE four table rename and four parallel transactions
# group: [rename_table]
statement ok
SET immediate_transaction_mode=true
statement ok con1
CREATE TABLE tbl1(i INTEGER)
statement ok con1
INSERT INTO tbl1 VALUES (999), (100)
# rename chain
# con2 starts a transaction now
statement ok con2
BEGIN TRANSACTION
# rename in con1, con2 should still see "tbl1"
statement ok con1
ALTER TABLE tbl1 RENAME TO tbl2
# con3 starts a transaction now
statement ok con3
BEGIN TRANSACTION
# rename in con1, con3 should still see "tbl2"
statement ok con1
ALTER TABLE tbl2 RENAME TO tbl3
# con4 starts a transaction now
statement ok con4
BEGIN TRANSACTION
# rename in con1, con4 should still see "tbl3"
statement ok con1
ALTER TABLE tbl3 RENAME TO tbl4
# con2 sees ONLY tbl1
query I con2
SELECT * FROM tbl1
----
999
100
statement error con2
SELECT * FROM tbl2
----
statement error con2
SELECT * FROM tbl3
----
statement error con2
SELECT * FROM tbl4
----
# con3 sees ONLY tbl2
statement error con3
SELECT * FROM tbl1
----
query I con3
SELECT * FROM tbl2
----
999
100
statement error con3
SELECT * FROM tbl3
----
statement error con3
SELECT * FROM tbl4
----
# con4 sees ONLY tbl3
statement error con4
SELECT * FROM tbl1
----
statement error con4
SELECT * FROM tbl2
----
query I con4
SELECT * FROM tbl3
----
999
100
statement error con4
SELECT * FROM tbl4
----
# con1 sees ONLY tbl4
statement error con1
SELECT * FROM tbl1
----
statement error con1
SELECT * FROM tbl2
----
statement error con1
SELECT * FROM tbl3
----
query I con1
SELECT * FROM tbl4
----
999
100

View File

@@ -0,0 +1,91 @@
# name: test/sql/alter/rename_table/test_rename_table_transactions.test
# description: Test RENAME TABLE two parallel transactions
# group: [rename_table]
statement ok con1
CREATE TABLE tbl(i INTEGER)
statement ok con1
INSERT INTO tbl VALUES (999), (100)
statement ok con1
BEGIN TRANSACTION
statement ok con2
BEGIN TRANSACTION
statement ok con1
ALTER TABLE tbl RENAME TO tbl2
query I con1
SELECT * FROM tbl2
----
999
100
statement error con1
SELECT * FROM tbl
----
Catalog Error: Table with name tbl does not exist
query I con2
SELECT * FROM tbl
----
999
100
statement error con2
SELECT * FROM tbl2
----
Catalog Error: Table with name tbl2 does not exist
statement ok con1
COMMIT
statement ok con2
COMMIT
statement error con1
SELECT * FROM tbl
----
Catalog Error: Table with name tbl does not exist
statement error con2
SELECT * FROM tbl
----
Catalog Error: Table with name tbl does not exist
query I con1
SELECT * FROM tbl2
----
999
100
query I con2
SELECT * FROM tbl2
----
999
100
# we can create "tbl" again
statement ok con1
CREATE TABLE tbl(i INTEGER);
# tbl2 is still occupied though
statement error con1
CREATE TABLE tbl2(i INTEGER);
----
Catalog Error: Table with name "tbl2" already exists
# we can drop and re-create the table
statement ok con1
DROP TABLE tbl2;
statement ok con1
CREATE TABLE tbl2(i INTEGER);
# a rename fails now
statement error con1
ALTER TABLE tbl RENAME TO tbl2
----
Catalog Error: Could not rename "tbl" to "tbl2"

View File

@@ -0,0 +1,23 @@
# name: test/sql/alter/rename_table/test_rename_table_view.test
# description: Test RENAME TABLE with a view as entry
# group: [rename_table]
statement ok
CREATE TABLE tbl(i INTEGER)
statement ok
INSERT INTO tbl VALUES (999), (100)
statement ok
CREATE VIEW v1 AS SELECT * FROM tbl
statement error
ALTER TABLE v1 RENAME TO v2
----
query I
SELECT * FROM v1
----
999
100

View File

@@ -0,0 +1,31 @@
# name: test/sql/alter/rename_table/test_rename_table_with_dependency_check.test
# description: Test RENAME TABLE with dependency check
# group: [rename_table]
statement ok
CREATE TABLE t0 (c0 INT);
statement ok
CREATE UNIQUE INDEX i1 ON t0 (c0);
statement error
ALTER TABLE t0 RENAME TO t3;
----
Cannot alter entry "t0" because there are entries that depend on it
# t3 is not exist
statement ok
CREATE TABLE t3 (c0 INT);
statement error
ALTER TABLE t0 RENAME TO t4;
----
Cannot alter entry "t0" because there are entries that depend on it
statement ok
DROP TABLE t0;
statement error
ANALYZE t4;
----
Table with name t4 does not exist!

View File

@@ -0,0 +1,27 @@
# name: test/sql/alter/rename_table/test_rename_table_with_insert_transaction.test
# description: Test RENAME TABLE with insert transactions
# group: [rename_table]
statement ok con1
CREATE TABLE t1 (i INTEGER)
statement ok con1
INSERT INTO t1 VALUES (1)
statement ok con1
BEGIN TRANSACTION
statement ok con1
INSERT INTO t1 VALUES (2)
statement ok con1
ALTER TABLE t1 RENAME TO t2
statement ok con1
COMMIT
query I
SELECT * FROM t2
----
1
2