> I'd also like to know why it wouldn't work if the function was STABLE: > Since Postgres should know that it's not going to change over the course of > the query, couldn't it substitute the value as well?
You have not shown us the context, but I suspect you are wishing that the planner would assume that the function's result can't change between planning and execution. Unfortunately, it can.
OK. So then I'd like to inform the planner that I don't care if the GUC value changes after the database session has begun. I want it to get the value and substitute it out in the planning phase so that the planner can find and use the correct index.
Is there any way to do this without marking something immutable when it is not?