docs: def parse_psql_array(inp):
      """
      :param inp: a string encoding an array
      :return: the array of elements as represented by the input
      """
      inp = unescape_sql(inp)
      # Strip '{' and '}'
      if inp.startswith("{") and inp.endswith("}"):
          inp = inp[1:-1]
  
      lst = []
      elem = ""
      in_quotes, escaped = False, False
  
      for ch in inp:
          if escaped:
              elem += ch
              escaped = False
          elif ch == '"':
              in_quotes = not in_quotes
              escaped = False
          elif ch == '\\':
              escaped = True
          else:
              if in_quotes:
                  elem += ch
              elif ch == ',':
                  lst.append(elem)
                  elem = ""
              else:
                  elem += ch
              escaped = False
      if len(elem) > 0:
          lst.append(elem)
      return lst