The problem I’m having
For PostgreSQL configs, dbt creates indexes with names that are a hash of its properties and the current timestamp. What’s a good way for me to reference these generated index names? Is there a way to customize or set the name of the index?
The context of why I’m trying to do this
I’d like to add a post hook to CLUSTER tables. CLUSTER
takes the name of an index to order the table rows by. But, there isn’t an obvious way to figure out the name of the indexes created by dbt-postgres.
What I’ve already tried
I briefly tried to find the implementation for the index name in the code. But, couldn’t see where it was.
Some example code or error messages
None
Not a direct answer to your question, but I think this is where the index name is calculated: https://github.com/dbt-labs/dbt-core/blob/main/plugins/postgres/dbt/adapters/postgres/impl.py#L39
Note: @Owen
originally posted this reply in Slack. It might not have transferred perfectly.
Thanks, that helps. Looks like it’s going to be impossible to generate a matching index name for CLUSTER
later on since it gets the datetime on every call.
Perhaps you could do something clever by querying <http://pg_catalog.pg|pg_catalog.pg>_indexes
system catalog view? https://www.postgresql.org/docs/current/view-pg-indexes.html
Note: @Owen
originally posted this reply in Slack. It might not have transferred perfectly.