cockroachdb / cockroach

CockroachDB - the open source, cloud-native distributed SQL database.
https://www.cockroachlabs.com
Other
29.51k stars 3.7k forks source link

sql: ALTER COLUMN TYPE on virtual column fails #125840

Open spilchen opened 2 weeks ago

spilchen commented 2 weeks ago

Describe the problem

Any attempt to alter the column type of a computed virtual column will result in an error.

To Reproduce

What did you do?

demo@127.0.0.1:26257/demoapp/movr> SET enable_experimental_alter_column_type_general = true;
SET

Time: 1ms total (execution 1ms / network 0ms)

demo@127.0.0.1:26257/demoapp/movr> create table t1 (real1 int, comp1 int as (real1 * 2) virtual);
CREATE TABLE

Time: 7ms total (execution 7ms / network 0ms)

demo@127.0.0.1:26257/demoapp/movr> alter table t1 alter column comp1 type float;
ERROR: no column family found for column id 2

Expected behavior Postgres does not support virtual columns yet, but it does support stored computed columns. It also allows altering the type of these stored computed columns. So, the expected behaviour here is to allow it as well.

Epic CRDB-25314

Jira issue: CRDB-39631

blathers-crl[bot] commented 2 weeks ago

Hi @spilchen, please add branch-* labels to identify which branch(es) this C-bug affects.

:owl: Hoot! I am a Blathers, a bot for CockroachDB. My owner is dev-inf.

rafiss commented 2 weeks ago

Nice find! Do you know what the expected behavior is if the new type is not compatible with the original computed column expression?

spilchen commented 2 weeks ago

Good suggestion. Yeah, it works if going from int->bigint.

demo@127.0.0.1:26257/demoapp/movr> alter table t1 alter column comp1 type bigint;
ALTER TABLE