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,17 @@
# name: test/sql/alter/rename_col/test_rename_col.test
# description: Test ALTER TABLE RENAME COLUMN
# group: [rename_col]
statement ok
CREATE TABLE test(i INTEGER, j INTEGER)
# rename the column
statement ok
ALTER TABLE test RENAME COLUMN i TO k
statement ok
SELECT * FROM test
statement ok
DROP TABLE IF EXISTS test

View File

@@ -0,0 +1,27 @@
# name: test/sql/alter/rename_col/test_rename_col_check.test
# description: Test ALTER TABLE RENAME COLUMN on a table with constraints: CHECK constraint
# group: [rename_col]
# create a table with a check constraint referencing the to-be-renamed column
statement ok
CREATE TABLE test(i INTEGER CHECK(i < 10), j INTEGER)
statement ok
INSERT INTO test (i, j) VALUES (1, 2), (2, 3)
statement error
INSERT INTO test (i, j) VALUES (100, 2)
----
Constraint Error: CHECK constraint failed
statement ok
ALTER TABLE test RENAME COLUMN i TO k
# the check should still work after the alter table
statement ok
INSERT INTO test (k, j) VALUES (1, 2), (2, 3)
statement error
INSERT INTO test (k, j) VALUES (100, 2)
----
Constraint Error: CHECK constraint failed

View File

@@ -0,0 +1,28 @@
# name: test/sql/alter/rename_col/test_rename_col_dependencies.test
# description: Test ALTER TABLE RENAME COLUMN and dependencies
# group: [rename_col]
statement ok
CREATE TABLE test(i INTEGER, j INTEGER)
# create two prepared statements
# one uses specific columns (i, j)
# the other uses select *
statement ok
PREPARE v1 AS SELECT i, j FROM test
statement ok
PREPARE v2 AS SELECT * FROM test
# now rename "i" to "k"
statement ok
ALTER TABLE test RENAME COLUMN i TO k
# v1 does not work anymore: "i" does not exist
statement error
EXECUTE v1
----
# v2 still works
statement ok
EXECUTE v2

View File

@@ -0,0 +1,21 @@
# name: test/sql/alter/rename_col/test_rename_col_failure.test
# description: Test failure conditions of ALTER TABLE
# group: [rename_col]
statement ok
CREATE TABLE test(i INTEGER, j INTEGER)
# cannot rename a column that does not exist
statement error
ALTER TABLE test RENAME COLUMN blablabla TO k
----
# cannot rename a column to an already existing column
statement error
ALTER TABLE test RENAME COLUMN i TO j
----
# after failure original columns should still be there
statement ok
SELECT i, j FROM test

View File

@@ -0,0 +1,26 @@
# name: test/sql/alter/rename_col/test_rename_col_not_null.test
# description: Test ALTER TABLE RENAME COLUMN on a table with constraints: NOT NULL constraint
# group: [rename_col]
statement ok
CREATE TABLE test(i INTEGER NOT NULL, j INTEGER)
statement ok
INSERT INTO test (i, j) VALUES (1, 2), (2, 3)
statement error
INSERT INTO test (i, j) VALUES (NULL, 2)
----
Constraint Error: NOT NULL constraint failed: test.i
statement ok
ALTER TABLE test RENAME COLUMN i TO k
# the not null constraint should still work after altering the table
statement ok
INSERT INTO test (k, j) VALUES (1, 2), (2, 3)
statement error
INSERT INTO test (k, j) VALUES (NULL, 2)
----
Constraint Error: NOT NULL constraint failed: test.k

View File

@@ -0,0 +1,36 @@
# name: test/sql/alter/rename_col/test_rename_col_rollback.test
# description: Test ALTER TABLE RENAME COLUMN with rollback
# group: [rename_col]
# CREATE TABLE
statement ok
CREATE TABLE test(i INTEGER, j INTEGER)
statement ok
START TRANSACTION
# rename the column in the first transaction
statement ok
ALTER TABLE test RENAME COLUMN i TO k
# now we should see the new name
statement error
SELECT i FROM test
----
Binder Error: Referenced column "i" not found in FROM clause
statement ok
SELECT k FROM test
# rollback
statement ok
ROLLBACK
# now we should see the old name again
statement ok
SELECT i FROM test
statement error
SELECT k FROM test
----
Binder Error: Referenced column "k" not found in FROM clause

View File

@@ -0,0 +1,62 @@
# name: test/sql/alter/rename_col/test_rename_col_transactions.test
# description: Test ALTER TABLE RENAME COLUMN with transactions
# group: [rename_col]
# CREATE TABLE
statement ok con1
CREATE TABLE test(
i INTEGER,
j INTEGER
)
# start two transactions
statement ok con1
START TRANSACTION
statement ok con2
START TRANSACTION
# rename column in first transaction
statement ok con1
ALTER TABLE test RENAME COLUMN i TO k
# first transaction should see the new name
statement error con1
SELECT i FROM test
----
statement ok con1
SELECT k FROM test
# second transaction should still consider old name
statement ok con2
SELECT i FROM test
statement error con2
SELECT k FROM test
----
# now commit
statement ok con1
COMMIT
# second transaction should still see old name
statement ok con2
SELECT i FROM test
statement error con2
SELECT k FROM test
----
# now rollback the second transasction
# it should now see the new name
statement ok con2
COMMIT
statement error con1
SELECT i FROM test
----
statement ok
SELECT k FROM test

View File

@@ -0,0 +1,27 @@
# name: test/sql/alter/rename_col/test_rename_col_unique.test
# description: Test ALTER TABLE RENAME COLUMN on a table with constraints: UNIQUE constraint
# group: [rename_col]
statement ok
CREATE TABLE test(i INTEGER, j INTEGER, PRIMARY KEY(i, j))
statement ok
INSERT INTO test (i, j) VALUES (1, 1), (2, 2)
statement error
INSERT INTO test (i, j) VALUES (1, 1)
----
Constraint Error: Duplicate key "i: 1, j: 1"
statement ok
ALTER TABLE test RENAME COLUMN i TO k
# the unique constraint should still work after altering the table
# error message refers to the old name of the column (was i, renamed to k)
statement ok
INSERT INTO test (k, j) VALUES (3, 3), (4, 4)
statement error
INSERT INTO test (k, j) VALUES (1, 1)
----
Constraint Error: Duplicate key