Unable to create distributed table with enum column in a transaction
- Dominant language
- C
- Stars
- 12.8k
- Forks
- 794
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 31
Description
## Versions
PostgreSQL version: 16
Citus version: 12.1
## Replication
Connect to a multi-node cluster and run this transaction:
❌
```sql
begin;
SET LOCAL citus.multi_shard_modify_mode TO 'sequential';
CREATE TYPE status_enum AS ENUM ('PENDING', 'STARTED', 'CANCELLED', 'COMPLETED', 'ERROR');
CREATE TABLE job (
id SERIAL NOT NULL,
status status_enum NOT NULL,
tenant_id INTEGER NOT NULL
);
SELECT create_distributed_table('job', 'tenant_id');
end;
```
#### Issue: citus failed with
```
SQL Error [42P01]: ERROR: relation "public.job_id_seq" does not exist
Where: while executing command on private-w1-xxxxxxxxx:5432
```
However executing these queries in sequence (no transaction) works as expected.
## Workaround
Set the enum column to `VARCHAR` temporarily, create table and change it back to the correct type
✅
```sql
begin;
SET LOCAL citus.multi_shard_modify_mode TO 'sequential';
CREATE TYPE status_enum AS ENUM ('PENDING', 'STARTED', 'CANCELLED', 'COMPLETED', 'ERROR');
CREATE TABLE job (
id SERIAL NOT NULL,
status VARCHAR NOT NULL,
tenant_id INTEGER NOT NULL
);
SELECT create_distributed_table('job', 'tenant_id');
ALTER TABLE job ALTER COLUMN status TYPE status_enum USING status::status_enum;
end;
```
Contributor guide
Assessment
This issue has not been assessed yet.