Skip to content

Commit c70fe13

Browse files
Added checking of available columns when receiving a subscription from the database (#437) (#440)
Co-authored-by: aleksvagachev <[email protected]> (cherry picked from commit 5fa5334) Co-authored-by: Aleks Vagachev <[email protected]>
1 parent 756f602 commit c70fe13

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Diff for: changelogs/fragments/0-postgresql_info.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- postgresql_info - when getting information about subscriptions, check the list of available columns in the pg_subscription table (https://github.com/ansible-collections/community.postgresql/issues/429).

Diff for: plugins/modules/postgresql_info.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@
281281
- Information about replication subscriptions (available for PostgreSQL 10 and higher)
282282
U(https://www.postgresql.org/docs/current/logical-replication-subscription.html).
283283
- Content depends on PostgreSQL server version.
284+
- The return values for the superuser and the normal user may differ
285+
U(https://www.postgresql.org/docs/current/catalog-pg-subscription.html).
284286
returned: if configured
285287
type: dict
286288
sample:
@@ -679,12 +681,19 @@ def get_pub_info(self):
679681

680682
def get_subscr_info(self):
681683
"""Get subscription statistics."""
682-
query = ("SELECT s.*, r.rolname AS ownername, d.datname AS dbname "
684+
columns_sub_table = ("SELECT column_name "
685+
"FROM information_schema.columns "
686+
"WHERE table_schema = 'pg_catalog' "
687+
"AND table_name = 'pg_subscription'")
688+
columns_result = self.__exec_sql(columns_sub_table)
689+
columns = ", ".join(["s.%s" % column[0] for column in columns_result])
690+
691+
query = ("SELECT %s, r.rolname AS ownername, d.datname AS dbname "
683692
"FROM pg_catalog.pg_subscription s "
684693
"JOIN pg_catalog.pg_database d "
685694
"ON s.subdbid = d.oid "
686695
"JOIN pg_catalog.pg_roles AS r "
687-
"ON s.subowner = r.oid")
696+
"ON s.subowner = r.oid" % columns)
688697

689698
result = self.__exec_sql(query)
690699

0 commit comments

Comments
 (0)