Skip to content

Conversation

NickCrews
Copy link
Contributor

@NickCrews NickCrews commented Mar 22, 2025

With a single Enum column definition in a schema, we don't actaully create and use the custom type, but make an inline copy every time. This is what currently happens:

CREATE TYPE severity AS ENUM ( 'LOW', 'MEDIUM', 'HIGH' );
CREATE TABLE bugs(severity ENUM('LOW', 'MEDIUM', 'HIGH'));

This is what I would expect:

CREATE TYPE severity AS ENUM ( 'LOW', 'MEDIUM', 'HIGH' );
CREATE TABLE bugs(severity severity);

If you point me in the right direction I can do the grunt work of actually writing the fix, but I just tried exploring where in our engine we would need to make adjustments so that sqlalchemy picks up the needed DDL hooks before table creation, and I got overwhelmed by the complexity of sqlalchemy.

@Mause
Copy link
Owner

Mause commented Mar 29, 2025

unfortunately i don't think this is really fixable from our side - duckdb itself doesn't retain a reference (last i checked) to the enum, but copies the enum definition itself. we can fix the sql at least though - can you fix the tests?

@NickCrews
Copy link
Contributor Author

duckdb itself doesn't retain a reference

Sorry, I don't think I understand, can you elaborate a bit more?

If I do

CREATE TYPE severity AS ENUM ( 'LOW', 'MEDIUM', 'HIGH' );
CREATE TABLE bugs(severity severity);
INSERT INTO bugs VALUES ('LOW'), ('HIGH');
DROP TYPE severity;

I get

Dependency Error: Cannot drop entry "severity" because there are entries that depend on it.
table "bugs" depends on type "severity".
Use DROP...CASCADE to drop all dependents.

which looks to me like the table is holding onto a reference to the type? This is the behavior that I want. Say I decide to change my enum to be 'L', 'M', 'H', instead. If I have 'LOW', 'MEDIUM', 'HIGH' stored inside the table, I want to get an error, because I need to explicitly do the conversion myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants