-
Notifications
You must be signed in to change notification settings - Fork 4.1k
sql: ALTER COLUMN TYPE does not check computed column definitions #72457
Copy link
Copy link
Closed
Labels
A-schema-changesC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Description
Describe the problem
If a computed column definition references a column whose type is changed, it can make it impossible to insert data.
To Reproduce
root@:26257/defaultdb> set enable_experimental_alter_column_type_general='true';
root@:26257/defaultdb> create table a (a int primary key, b text, c int as (length(b)) stored);
root@:26257/defaultdb> alter table a alter column b set data type int;
root@:26257/defaultdb> insert into a values (1,1);
ERROR: unknown signature: length(int) (desired <int>)
SQLSTATE: 42883
Expected behavior
The ALTER should error, like what Postgres does:
postgres=# create table a (a int primary key, b text, c int generated always as (length(b)) stored);
CREATE TABLE
postgres=# alter table a alter column b set data type int using b::integer;
ERROR: cannot alter type of a column used by a generated column
DETAIL: Column "b" is used by generated column "c".
Jira issue: CRDB-11165
Epic CRDB-25314
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-schema-changesC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)SQL Foundations Team (formerly SQL Schema + SQL Sessions)