How to use query time calculations in model? #1079
Unanswered
20-buck-spin
asked this question in
Questions
Replies: 1 comment
-
So after a huge bunch of testing, this works only if the column does indeed exist in the table (I created a column that will always be null)
As I understand, this isn't the desired behaviour? Should I create an issue on it? I could try looking for a solution if someone can give me hints on where to start. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
As the title suggests, I am trying to implement query time computed values for a model (the real example is complex with subqueries, etc. so i am presenting a simplified example)
Given the StoreItem class above, how can I create a query that does something like
select(StoreItem).options(with_expression(StoreItem.min_price, sql_func.func.least(StoreItem.price_a, StoreItem.price_b))
I found the SqlAlchemy docs in query_expression() and with_expression(). But when trying to use them, I get the error 'asyncpg.exceptions.UndefinedColumnError' because the query_expression column does not exist in the database.
I am assuming I may need to somehow approach this problem differently in the context of SqlModel. Any help would be much appreciated.
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.21
Python Version
3.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions