I'm trying to add a default value to an enum column so a unique constraint will only allow one null like so:
CREATE UNIQUE INDEX "some_index" on some_table (coalesce(some_enum_column::text, 'some_default_value'));
Basically, I'm trying to replace Postgres-15's new NULLS NOT DISTINCT
feature in Postgres-14.5
And I'm getting this error:
functions in index expression must be marked IMMUTABLE
From reading online and from this answer, I understand that this cast is problematic because the enum values can change, making this cast mutable.
But if this is the case, how does Postgres index an enum column normally? What is the difference between the enum and its string representation in this case?
Does it have some trigger to reindex on enum change?
I could use a partial index in this example but in reality, my index includes multiple columns, some nullable and some not.
I'm writing an extension to an ORM, so I need to be able to support an arbitrary amount of nullable columns.