New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to select columns of different type in SQLAlchemy in the where clause? #4444
Comments
the mailing list is more appropriate but since github gives us the "question" label we can handle it
that might be kind of database specific, in that I bet SQLite would let it go right through, but Postgresql would not. I'd be curious to see what the error message you are getting is.
I think what you need to do is have the expression that's coming out on the left hand side respond to the kind of right hand expression you are comparing towards. The other way is to just cast both sides to a string. For either one, you'd need to use the |
related bug is #4446 |
Hi thanks, I will take a look into the |
Hi, first I want to say sorry if this is not the right place to ask this question. I have a following table in sqlalchemy:
This is to model the EAV model which fits my business purpose.
Now to use it easily in the code I have the following
hybrid_property
.This works fine when I try to get and set the fields in Python code. But I still have a problem:
This does not work out of the box but I had an idea of using hybrid.expression where we use a case statement:
This in theory works, for example, the SQL generated for query
session.query(EAVTable.value = 123
looks like:Which semantically looks like what I like, but later I find that the
case
expression requires all the cases have the same type, or they are cast into the same type.I understand this is a requirement from the SQL language and has nothing to do with sqlachemy, but for more seasoned sqlalchemy user, is there any easy way to do what I want to achieve? Is there a way to walk around this constraint?
The text was updated successfully, but these errors were encountered: