Github user njayaram2 commented on a diff in the pull request:

    https://github.com/apache/madlib/pull/274#discussion_r193525463
  
    --- 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 --
    
    True, but I feel having a single `,` at the end of a string is something 
that can occur easily.  In other words, having a single `,` at the end of a 
string is probably more likely to happen than the test cases we cover in the 
corresponding install check files in this PR.
    
    We don't need a super obscure delimiter, but `,,,` seems too simple.


---

Reply via email to