Annotate on recursive relation giving error on PostgreSQL
See original GitHub issueHello, I’m getting this PG error while trying to do a count on a recursive relationship.
tortoise.exceptions.OperationalError: column “task.estimated_start_date” must appear in the GROUP BY clause or be used in an aggregate function
class Task(BaseModel):
mother = fields.ForeignKeyField('models.Task', null=True, related_name="children")
#Some code later...
tasks = await Task.filter(mother=None).annotate(children_count=Count("children"))
Am I doing something wrong?
What I’m trying to achieve with my query, is a hierarchical view of the tasks, first I’m getting the “outer” ones, and then checking if they have any children so then I will display a dropdown arrow that will asynchronous load the children and so on.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
7.8. WITH Queries (Common Table Expressions) - PostgreSQL
Evaluate the non-recursive term. For UNION (but not UNION ALL ), discard duplicate rows. · So long as the working table is not...
Read more >Recursive queries in PostgreSQL - an introduction - CYBERTEC
This article gives a simple introduction with examples to recursive queries in PostgreSQL. It also includes a comparison to Oracle recursive ...
Read more >Postgres Recursive Query(CTE) or Recursive Function?
But the recursive function gives me ERROR: stack depth limit exceeded. HINT: Increase the configuration parameter “max_stack_depth” (currently ...
Read more >Cast produces 'Returned type character varying does not ...
If the first column of that type (table) is defined varchar(8) (with length modifier) - as the error message indicates, you have to...
Read more >How does GRANT privileges function when recursive ...
So the question is, is this the expected behaviour on PostgreSQL/any RDBMS, or am I understanding wrong how SQL privileges should work.
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
Release 0.16.4 os out with the fix, please confirm.
It should be fixed in next release. You can test out develop doing a
pip install https://github.com/tortoise/tortoise-orm/archive/develop.zip