diff --git a/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml b/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml new file mode 100644 index 00000000000..2af7242211a --- /dev/null +++ b/changelogs/fragments/65679-postgresql_schema_user_query_params_with_cursor.yml @@ -0,0 +1,2 @@ +bugfixes: +- postgresql_schema - use query parameters with cursor object (https://github.com/ansible/ansible/pull/65679). diff --git a/lib/ansible/modules/database/postgresql/postgresql_schema.py b/lib/ansible/modules/database/postgresql/postgresql_schema.py index 3fc4d06030a..9781a7387ac 100644 --- a/lib/ansible/modules/database/postgresql/postgresql_schema.py +++ b/lib/ansible/modules/database/postgresql/postgresql_schema.py @@ -165,15 +165,15 @@ def set_owner(cursor, schema, owner): def get_schema_info(cursor, schema): query = ("SELECT schema_owner AS owner " "FROM information_schema.schemata " - "WHERE schema_name = '%s'" % schema) - cursor.execute(query) + "WHERE schema_name = %(schema)s") + cursor.execute(query, {'schema': schema}) return cursor.fetchone() def schema_exists(cursor, schema): query = ("SELECT schema_name FROM information_schema.schemata " - "WHERE schema_name = '%s'" % schema) - cursor.execute(query) + "WHERE schema_name = %(schema)s") + cursor.execute(query, {'schema': schema}) return cursor.rowcount == 1