Skip to content

Commit

Permalink
sql: Add test showing manual column type change
Browse files Browse the repository at this point in the history
This test verifies that it's possible to effect a non-trivial column type
change using the current state of the system and verifies the planned strategy
for ALTER COLUMN TYPE.

Release note: None
  • Loading branch information
bobvawter committed May 24, 2018
1 parent f501757 commit 7be5d91
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/alter_column_type
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,65 @@ statement ok
DROP TABLE t


# Demonstrate manual flow for non-trivial column change
subtest ManualGeneralChange

statement ok
CREATE TABLE t (a INT PRIMARY KEY, b STRING)

statement ok
CREATE INDEX idx ON t (b)

statement ok
INSERT INTO t VALUES (1, '01'), (2, '002'), (3, '0003')

query IT colnames
SELECT * from t ORDER BY b DESC
----
a b
1 01
2 002
3 0003

statement ok
ALTER TABLE t ADD COLUMN i INT as (b::INT) STORED

statement ok
CREATE INDEX idx2 ON t (i)

statement ok
ALTER TABLE t ALTER COLUMN i DROP STORED, DROP COLUMN b CASCADE

query TT colnames
show create table t
----
Table CreateTable
t CREATE TABLE t (
a INT NOT NULL,
i INT NULL,
CONSTRAINT "primary" PRIMARY KEY (a ASC),
INDEX idx2 (i ASC),
FAMILY "primary" (a, i)
)

statement ok
ALTER TABLE t RENAME COLUMN i TO b

statement ok
ALTER INDEX idx2 RENAME TO idx

query II colnames
SELECT * from t ORDER BY b DESC
----
a b
3 3
2 2
1 1

statement ok
DROP TABLE t CASCADE


# Demonstrate that we can change to an alias of a type
subtest ChangeVisibleColumnType

Expand Down

0 comments on commit 7be5d91

Please sign in to comment.