-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Lost type of aliased column from subquery #2248
Comments
That's correct, and peewee will figure it out correctly most of the time, but when you're pulling stuff up from subqueries you may need to explicitly tell peewee how to coerce it. Did you try: .select(MyModel.date, sub.c.date, sub.c.date, sub.c.aliased.coerce(MyModel.date.db_value)) |
Your proposition does not seem to work. the best thing I managed to do was to use MyModel.date.python_value on the result MyModel.date.python_value(row['aliased']) |
Whoops, I meant |
Yes,I tried it did not work either |
Sorry, I had my APIs mixed-up. I've added a new API for this case, which may change somewhat before the next release -- but this should provide a way forward for these cases that aren't covered by the existing heuristics. The new API would be: .select(..., subq.c.aliased.converter(callable)) And |
Now I don`t use subquery . But after used cast sting to int,I use alias I get string not a int value |
Possibly you are aliasing it to the same name as used by an existing char/text field on your model? |
You are right, now i use round function to cast string to decimal |
If you alias an expression to the name of an existing column, peewee assumes you want to use that column's conversions for the data. So you might try also just using a different name - one that doesn't coincide with an existing field. |
Hi,
when using aliased colums in a subquery, peewee seems to loose the type of the column
In the following script, I access a date from a subquery, with and without an alias.
Without the alias, I get a python date as expected, but with the alias, I get a string
Am I doing something wrong? From the doc, using aliases seemed to be the recommended way to access the subquery columns
The text was updated successfully, but these errors were encountered: