Carbunql icon indicating copy to clipboard operation
Carbunql copied to clipboard

Dealing with cases where CTE names and physical tables collide

Open mk3008 opened this issue 7 months ago • 0 comments

There is a technique to "intentionally" make CTE and physical table names the same. We will deal with this.

Sample

with
sale_summarys as (
    select
        store_id
        , sum(price) as price
    from
        --Physical
        sales
    group by
        store_id
),
sales as (
    select
        *
    from
        --Physical
        sales
)
select
    *
from
    --CTE
    sale_summarys
;
with
sales as (
    select
        *
    from
        --Physical
        sales
),
sale_summarys as (
    select
        store_id
        , sum(price) as price
    from
        --CTE
        sales
    group by
        store_id
)
select
    *
from
    --CTE
    sale_summarys

mk3008 avatar Jul 21 '24 23:07 mk3008