Skip to content

Complex SQL Queries on Ormar (Window Functions, Partition, Not Exists and Nested Selects) #460

Answered by collerek
igormorgado asked this question in Q&A
Discussion options

You must be logged in to vote

Since each query in ormar starts and ends with a pydantic/ormar model it's currently not possible through ormar (i.e. there is no column danse_rank in your model so ormar would have to create it on the fly and infer a type properly, there are discussions and issues around ctes and other functions but it's not implemented yet).

Your best call is to simply execute a raw query that you already have and you can do so through databases: https://www.encode.io/databases/database_queries/#raw-queries

Note that you have to use the same databases that is used in model's Meta.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igormorgado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants