Skip to content

Commit 70c6b11

Browse files
committed
postgresql_query, postgresql_script: don't convert list arguments to postgres arrays - let psycopg2 do it
1 parent 984bf53 commit 70c6b11

File tree

3 files changed

+0
-50
lines changed

3 files changed

+0
-50
lines changed

plugins/module_utils/postgres.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -396,44 +396,6 @@ def set_search_path(cursor, search_path):
396396
cursor.execute('SET search_path TO %s' % search_path)
397397

398398

399-
def convert_elements_to_pg_arrays(obj):
400-
"""Convert list elements of the passed object
401-
to PostgreSQL arrays represented as strings.
402-
403-
Args:
404-
obj (dict or list): Object whose elements need to be converted.
405-
406-
Returns:
407-
obj (dict or list): Object with converted elements.
408-
"""
409-
if isinstance(obj, dict):
410-
for (key, elem) in iteritems(obj):
411-
if isinstance(elem, list):
412-
obj[key] = list_to_pg_array(elem)
413-
414-
elif isinstance(obj, list):
415-
for i, elem in enumerate(obj):
416-
if isinstance(elem, list):
417-
obj[i] = list_to_pg_array(elem)
418-
419-
return obj
420-
421-
422-
def list_to_pg_array(elem):
423-
"""Convert the passed list to PostgreSQL array
424-
represented as a string.
425-
426-
Args:
427-
elem (list): List that needs to be converted.
428-
429-
Returns:
430-
elem (str): String representation of PostgreSQL array.
431-
"""
432-
elem = str(elem).strip('[]')
433-
elem = '{' + elem + '}'
434-
return elem
435-
436-
437399
def convert_to_supported(val):
438400
"""Convert unsupported type to appropriate.
439401
Args:

plugins/modules/postgresql_query.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@
317317
)
318318
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
319319
connect_to_db,
320-
convert_elements_to_pg_arrays,
321320
convert_to_supported,
322321
ensure_required_libs,
323322
get_conn_params,
@@ -442,11 +441,6 @@ def main():
442441
else:
443442
args = None
444443

445-
# Convert elements of type list to strings
446-
# representing PG arrays
447-
if args:
448-
args = convert_elements_to_pg_arrays(args)
449-
450444
# Set defaults:
451445
changed = False
452446

plugins/modules/postgresql_script.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@
225225
)
226226
from ansible_collections.community.postgresql.plugins.module_utils.postgres import (
227227
connect_to_db,
228-
convert_elements_to_pg_arrays,
229228
convert_to_supported,
230229
ensure_required_libs,
231230
get_conn_params,
@@ -299,11 +298,6 @@ def main():
299298
else:
300299
args = None
301300

302-
# Convert elements of type list to strings
303-
# representing PG arrays
304-
if args:
305-
args = convert_elements_to_pg_arrays(args)
306-
307301
# Execute script content:
308302
try:
309303
cursor.execute(script_content, args)

0 commit comments

Comments
 (0)