Unwanted 'AS' when constructing HAVING clause
See original GitHub issueHi!
When I use my peewee.Func object, which has _alias, in having(…), then Peewee adds keyword ‘AS’ in clause.
For example:
field = fn.Count(SystemUser.id).alias('roles_count')
query = query.having(field == 2)
Then I get syntax error:
…name" HAVING ((Count(“t1”.“id”) AS roles_count…
I construct queries automatically from rest-requests, so I need to take fields from query.get_query_meta()[0] for comparing with requests and constructing query.
It is easy just clean _alias before constructing query and problem will go away, but nevertheless I think that it is strange behavior.
Thanks for attention!
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Ignore Field used in HAVING clause on SELECT
The easiest way is to use a simple subquery: SELECT id, name, -- midpointlevel, <-- commented out, since we don't need this column...
Read more >4. Filtering - Learning SQL, 3rd Edition [Book] - O'Reilly
This chapter explores the various types of filter conditions that you can employ in the where clauses of select , update , and...
Read more >7 Common GROUP BY Errors - LearnSQL.com
1. Forgetting GROUP BY with Aggregate Functions ... You use SELECT statements with the GROUP BY clause when you want to group and...
Read more >mysql - Query with HAVING clause is taking too long
WHERE is done while gathering rows; HAVING is done after all the rows are gathered. That is, WHERE is more efficient. However, HAVING...
Read more >SQL HAVING Clause - W3Schools
The HAVING clause was added to SQL because the WHERE keyword cannot be used with aggregate functions. HAVING Syntax. SELECT column_name(s) FROM table_name...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This “problem” has been present in peewee since at least version 2.0.0, and at present, exists in the 3.0 rewrite (which you can see here).
The typical way to handle this is to either:
alias()
when you need to.SQL()
object to reference the alias directly.Example 1:
Example 2:
This is fixed by e88dbf5145261890bc1a55a2f24ce6dfba36d8db in the 3.0a branch.