def to_sql(selection):
    """
    Convert selection to a SQL condition (i.e., something that may be used in a
    where clause).
    """
    if hasattr(selection, 'to_sql'):
        return selection.to_sql()
    return str(selection)
