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

Column name specified via AS can't be used in WHERE #46

Open
blais opened this issue Dec 12, 2018 · 5 comments
Open

Column name specified via AS can't be used in WHERE #46

blais opened this issue Dec 12, 2018 · 5 comments
Labels
enhancement New feature or request

Comments

@blais
Copy link
Member

blais commented Dec 12, 2018

Original report by Martin Michlmayr (Bitbucket: tbm13, GitHub: tbm).


I specify a column name via "AS foo" but then "WHERE foo" says that "foo" is an invalid column. It would be nice if it would recognise the custom column names I make via "AS".

beancount> SELECT ANY_META('entity') as entity WHERE ANY_META('entity') ~ 'Michlmayr';
 entity  
---------
Michlmayr
Michlmayr
Michlmayr
Michlmayr
beancount> SELECT ANY_META('entity') as entity WHERE entity ~ 'Michlmayr';
ERROR: Invalid column name 'entity' in WHERE clause context.
beancount> 
@blais
Copy link
Member Author

blais commented Dec 12, 2018

Original comment by Martin Michlmayr (Bitbucket: tbm13, GitHub: tbm).


It works in GROUP BY, btw.

@blais blais added P1 labels May 22, 2020
@blais blais transferred this issue from beancount/beancount Apr 3, 2022
@dnicolodi dnicolodi changed the title bql: column name specified via AS can't be used in WHERE Column name specified via AS can't be used in WHERE Apr 6, 2022
@dnicolodi dnicolodi added the enhancement New feature or request label Apr 8, 2022
@dnicolodi
Copy link
Collaborator

I implemented support for referring to columns names set with AS in the WHERE and HAVING clauses in #29. However, I am not sure this is a desirable feature.

Using the AS column names in WHERE and HAVING is not allowed by the SQL standard and is not supported by PostgreSQL (which is my SQL reference implementation) see "SELECT list" in https://www.postgresql.org/docs/current/sql-select.html SQLite supports this use, but the SQLite author wishes he could remove support for this https://www.mail-archive.com/[email protected]/msg94070.html

I see the convenience of being able to reference column aliases in the WHERE and HAVING clause but I wonder if I am missing some good reason not to support this that can come biting us down the road.

@blais
Copy link
Member Author

blais commented Oct 11, 2022 via email

@tbm
Copy link
Contributor

tbm commented Dec 1, 2022

I didn't realize this was not a standard SQL feature. I'm ok with this request being closed since this is not a standard SQL feature.

@blais
Copy link
Member Author

blais commented Dec 1, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants