refined handling of CTE

there was a bug "with x(...) as (select" case
in "with x as (select" case, use views instead of tables