question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotate on recursive relation giving error on PostgreSQL

See original GitHub issue

Hello, 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:closed
  • Created 3 years ago
  • Comments:15 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
grigicommented, Apr 3, 2020

Release 0.16.4 os out with the fix, please confirm.

1reaction
grigicommented, Mar 29, 2020

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found