def unquote_ident(val):
    """Unquotes possibly quoted SQL identifier.
    
    >>> unquote_ident('Foo')
    'foo'
    >>> unquote_ident('"Wei "" rd"')
    'Wei " rd'
    """
    if len(val) > 1 and val[0] == '"' and val[-1] == '"':
        return val[1:-1].replace('""', '"')
    if val.find('"') > 0:
        raise Exception('unsupported syntax')
    return val.lower()