Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combining function chaining and reusable aliases fails in where clause #11854

Open
2 tasks done
Alex-Monahan opened this issue Apr 26, 2024 · 0 comments
Open
2 tasks done

Comments

@Alex-Monahan
Copy link
Contributor

What happens?

Howdy folks!

I found a small issue when combining 2 of my favorite friendly SQL features.

If I combine the use of function chaining and reusable aliases together in my select clause, then use that column in my where clause, I receive an error.

To Reproduce

It seems to be something to do with the combination of the two. Using just function chaining or just reusable aliases works correctly in the where clause. However, both together fails.

-- Fails
with test as (
    select 'woot' as my_column
)
from test
select 
    my_column.substr(2) as partial_woot,
    partial_woot.substr(2) as more_partially_woot
where 
    more_partially_woot = 'ot'
;
Catalog Error: Scalar Function with name substr does not exist!
Did you mean "main.substr"?
LINE 7:     partial_woot.substr(2) as more_partially_woot
where 
    more_partially_woot = 'ot'
;...
            ^
-- Works: Multiple chains without reusable aliases
with test as (
    select 'woot' as my_column
)
from test
select 
    my_column.substr(2) as partial_woot,
    my_column.substr(2).substr(2) as more_partially_woot
where 
    more_partially_woot = 'ot'
;

-- Works: Single chain and reusing the alias in the where clause only
with test as (
    select 'woot' as my_column
)
from test
select 
    my_column.substr(2) as partial_woot,
where 
    partial_woot = 'oot'
;

-- Works: Reusable aliases that don't use function chaining
with test as (
    select 'woot' as my_column
)
from test
select 
    substr(my_column,2) as partial_woot,
    substr(partial_woot,2) as more_partially_woot
where 
    more_partially_woot = 'ot'
;

OS:

MacOS

DuckDB Version:

0.10.2, 0.10.3-dev388

DuckDB Client:

CLI

Full Name:

Alex Monahan

Affiliation:

DuckDB Labs and MotherDuck (lol at Oracle placeholder)

What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.

I have tested with a nightly build

Did you include all relevant data sets for reproducing the issue?

Not applicable - the reproduction does not require a data set

Did you include all code required to reproduce the issue?

  • Yes, I have

Did you include all relevant configuration (e.g., CPU architecture, Python version, Linux distribution) to reproduce the issue?

  • Yes, I have
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants