Skip to content

WITH statement inside subqueries #76353

@BlueskyFR

Description

@BlueskyFR

Company or project name

No response

Question

Hi! I noticed a strange behavior of the WITH statement when using subqueries.
For some reason this doesn't work:

with
    A = 2 as selector
select sum(value) from (
    select * from test_table where selector
    
    union all
    
    select * from test_table
)

While this DOES:

+select sum(value) from (
with
    A = 2 as selector
-select sum(value) from (
    select * from test_table where selector
    
    union all
    
    select * from test_table
)

I really want to write it the first way because I want to access some stuff in the global scope and it is less convenient to nest the WITH statements in my opinion.

So is it a behavior I did not get? If so, is that explained somewhere in the docs?

Thanks in advance 😊

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions