Skip to content

sql: ALTER COLUMN TYPE does not check partial index definitions #72456

@rafiss

Description

@rafiss

Describe the problem

If a partial index constraint references a column whose type is changed, it can make it impossible to insert data.

To Reproduce

set use_declarative_schema_changer = off; 

root@:26257/defaultdb> set enable_experimental_alter_column_type_general='true';

root@:26257/defaultdb> create table a (a int primary key, b text, c text);

root@:26257/defaultdb> create index idx on a(c) where b = 'cat';

root@:26257/defaultdb> alter table a alter column b set data type timestamp  using a::timestamp;

root@:26257/defaultdb> insert into a values (1,now(),'abc');
ERROR: unsupported comparison operator: <timestamp> = <string>
SQLSTATE: 22023

Expected behavior
The ALTER should be prevented, like how postgres does:

postgres=# create table a (a int primary key, b text, c text);
CREATE TABLE

postgres=# create index idx on a(c) where b = 'cat';
CREATE INDEX

postgres=# alter table a alter column b set data type timestamp using b::timestamp;
ERROR:  operator does not exist: timestamp without time zone = text

Jira issue: CRDB-11164
Epic CRDB-25314

Metadata

Metadata

Assignees

Labels

C-bugCode 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)branch-release-23.1Used to mark GA and release blockers, technical advisories, and bugs for 23.1branch-release-23.2Used to mark GA and release blockers, technical advisories, and bugs for 23.2branch-release-24.1Used to mark GA and release blockers, technical advisories, and bugs for 24.1branch-release-24.2Used to mark GA and release blockers, technical advisories, and bugs for 24.2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions