tortoise / tortoise/tortoise-orm

How to get a SubQuery in FROM clause?

Open
#1,234 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

My native SQL statement is:
SELECT vulnerability.*, vulnerability__agent.*, vulnerability__assembly.* FROM ( SELECT * FROM vulnerability WHERE task_id = '12345' ORDER BY name ASC LIMIT 10 ) vulnerability LEFT OUTER JOIN agent vulnerability__agentONvulnerability__agent.agent_id=vulnerability.agent_id LEFT OUTER JOIN plugin vulnerability__assemblyONvulnerability__assembly.assembly_id=vulnerability.assembly_id

Can it be supported in tortoise-orm?

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 reviewing Tortoise ORM's query API and its support for native SQL, then compare those entry points with the supplied SQL using a subquery in the FROM clause. Done means establishing whether this query shape is supported and, if not, defining the required ORM capability or documenting the limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, sql
Domain
backend, databases
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.