diff --git a/changelogs/fragments/693-idx-consider-schema.yaml b/changelogs/fragments/693-idx-consider-schema.yaml new file mode 100644 index 00000000..ee99338d --- /dev/null +++ b/changelogs/fragments/693-idx-consider-schema.yaml @@ -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. diff --git a/plugins/modules/postgresql_idx.py b/plugins/modules/postgresql_idx.py index a2566621..83d0a67b 100644 --- a/plugins/modules/postgresql_idx.py +++ b/plugins/modules/postgresql_idx.py @@ -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(