generate as clauses only where needed