postgresqlrestorepg-restorepostgresql-15

ERROR: functions in index expression must be marked IMMUTABLE in Postgres 15


On pg_restore Postgresql throws an error on index creation:

pg_restore: error: could not execute query: ERROR:  functions in index expression must be marked IMMUTABLE
Command was: CREATE INDEX inventory_package__name_index ON public.inventory_package USING gin (public.unaccent((name)::text) public.gin_trgm_ops);

Using Postgresql 15


Solution

  • Presumably someone altered the function to mark it immutable:

    alter function unaccent(text) immutable;
    

    But since the unaccent function is part of an extension (one also named "unaccent"), this marking is lost during a dump and restore. You would need to repeat the modification, assuming of course you think that that is the correct thing to do. It might be better to make a wrapper around the extension's unaccent function and declare that wrapper immutable, and use that. That way future upgrades will not have the same problem.