cockroachdb / cockroachdb/cockroach

sql: not possible to cast to enum UDT in partition values list

Open
#138,874 1 comment 0 reactions 0 assignees View on GitHub
A-sql-datatypes A-sql-typing branch-master branch-release-21.2 branch-release-22.1 branch-release-22.2 branch-release-23.1 branch-release-23.2 branch-release-24.1 branch-release-24.2 branch-release-24.3 C-bug T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

When we create a table with an enum user-defined type, we can cast various constants in the table definition to the type:

```sql
CREATE TYPE e AS ENUM ('e1', 'e2');
CREATE TABLE ab (
a e PRIMARY KEY DEFAULT 'e1'::e,
b e AS ('e2'::e) VIRTUAL
) PARTITION BY LIST (a) (PARTITION p VALUES IN (('e1')));
```

But when we try to cast the constants in the partition values list to the type, it fails with "type does not exist":

```sql
CREATE TYPE f AS ENUM ('f1', 'f2');
CREATE TABLE cd (
c f PRIMARY KEY DEFAULT 'f1'::f,
d f AS ('f2'::f) VIRTUAL
) PARTITION BY LIST (c) (PARTITION p VALUES IN (('f1'::f)));
-- fails with
-- ERROR: PARTITION p: type "f" does not exist
-- SQLSTATE: 42704
```

Jira issue: CRDB-46392

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.