tortoise / tortoise/tortoise-orm

[QUESTION] ARRAY_AGG function in the annotation

Open
#535 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
5.6k
Forks
516
Avg merge
2d 21h
Merged PRs (30d)
9

Description

Hi guys,

I'm wondering, is there any way to make an ARRAY_AGG aggregation in the .annotate method? I need an SQL like this:
SELECT table1.*, ARRAY_AGG(one2manytable.*) FROM table1 JOIN one2manytable ON table1.id. = one2manytable.fk_id

Unfortunately, I can't create a custom function, because basic tortoise.functions.Function only expects one field argument in the definition.

Much appreciated your help!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the .annotate entry point and tortoise.functions.Function, which the issue identifies as the relevant API. Compare their current argument model with the requested ARRAY_AGG SQL and determine the expected behavior for related rows. Done would require a resolved design and confirmed support or documentation, but no file or test is named here.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.