import re


def read_ptsv_element(x):
  """
  Parse an element in psql-compatible tsv format, i.e. {-format arrays
  Takes a string as input, handles float, int, str vals, and arrays of these types
  """
  if len(x) == 0:
    return None
  if x[0] == '{':
    return map(read_ptsv_element, re.split(r'\"?,\"?', re.sub(r'^\{\"?|\"?\}$', '', x)))
  for type_fn in [int, float, str]:
    try:
      return type_fn(x)
    except ValueError:
      pass
  raise ValueError("Type not recognized.")