Skip to content

Commit

Permalink
postgresql_idx: consider schema name when checking (#693)
Browse files Browse the repository at this point in the history
When checking to see if an index exists, the schema name needs to be
taken into account.  That is, the same name can exist in multiple
schemas.

Fixes #692

(cherry picked from commit 09fec84)
  • Loading branch information
rlaager authored and patchback[bot] committed May 10, 2024
1 parent b4027ef commit 5be67cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/693-idx-consider-schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- postgresql_idx - consider schema name when checking for index (https://github.com/ansible-collections/community.postgresql/issues/692). Index names are only unique within a schema. This allows using the same index name in multiple schemas.
5 changes: 3 additions & 2 deletions plugins/modules/postgresql_idx.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,10 @@ def __exists_in_db(self):
"ON i.indexname = c.relname "
"JOIN pg_catalog.pg_index AS pi "
"ON c.oid = pi.indexrelid "
"WHERE i.indexname = %(name)s")
"WHERE i.schemaname = %(schema)s "
"AND i.indexname = %(name)s")

res = exec_sql(self, query, query_params={'name': self.name}, add_to_executed=False)
res = exec_sql(self, query, query_params={'schema': self.schema, 'name': self.name}, add_to_executed=False)
if res:
self.exists = True
self.info = dict(
Expand Down

0 comments on commit 5be67cb

Please sign in to comment.