def get_headers(sql, prefix=None):
    """Returns a list of headers in an sql select string

    Parameters
    ----------
    sql : str
        SQL to get definition from. 
    prefix : str (optional)
        Characters to prefix to each header. 

    Returns
    -------
    list
        List of headers. 

    Examples
    --------
    >>> get_headers('SELECT a, b, c FROM x')
    ['a', 'b', 'c']

    >>> get_headers('SELECT a, b, c, FROM x', 'z')
    ['z.a', 'z.b' ,'z.c']
    """
    cols = []
    open_parenth = False
    clean_sql = ""
    # Remove anything in parentheses, liable to contain commas
    for i, char in enumerate(sql):
        if char == "(":
            open_parenth = True
        elif char == ")":
            open_parenth = False
        if not open_parenth:
            clean_sql += sql[i].replace("\t", " ")
    for col in clean_sql.split("FROM")[0].replace("SELECT", "").split(","):
        if " as " in col.lower():
            c = col.split(" as ")[-1]
        elif "." in col.lower():
            c = col.split(".")[-1]
        else:
            c = col
        cols.append(c.strip())
    if prefix != None:
        cols = [".".join([prefix, col]) for col in cols]
    return cols