Github user jingyimei commented on a diff in the pull request:
https://github.com/apache/madlib/pull/274#discussion_r193525716
--- Diff: src/ports/postgres/modules/utilities/utilities.py_in ---
@@ -296,11 +305,24 @@ def py_list_to_sql_string(array, array_type=None,
long_format=None):
if not array:
return "'{{ }}'::{0}".format(array_type)
else:
- array_str = "ARRAY[ {0} ]" if long_format else "'{{ {0} }}'"
- return (array_str + "::{1}").format(','.join(map(str, array)),
array_type)
+ # For non-character array types:
+ if long_format:
+ array_str = "ARRAY[ {0} ]";
+ return (array_str + "::{1}").format(
+ ','.join(map(str, array)), array_type)
+ else:
+ # For character array types, we have to deal with special
characters in
+ # elements an array, i.e, {'ele''one', "ele,two", "ele$three"} :
+ # We firstly use ",,," to join elements in python list and then
call
+ # postgres string_to_array with a delimiter ",,," to form the final
+ # psql array, because this sequence of characters will be very
+ # unlikely to show up in a real world use case and some special
+ # case (such as "M,M") will be handled.
+ array_str = "string_to_array($${0}$$, ',,,')"
+ return (array_str + "::{1}").format(
+ ',,,'.join(map(str, array)), array_type)
--- End diff --
Agree
---