Syntax error in built SQL query on Postgres
See original GitHub issueDescribe the bug On Postgres, if I have a model called User, and I do:
User.objects.get(foo=bar)
The generated SQL expression will cause a syntax error from Postgres:
syntax error at or near "."
The reason is, in the generated expression, we are quote escaping the table name everywhere except in the very last ‘Order by’ statement. I.e we get:
SELECT “user”.id AS id FROM “user” WHERE “user”.foo = ‘bar’ ORDER BY user.id
Not having the table name in quotes in the order by statement causes the syntax error in postgres
Is there a workaround available for now @collerek ?
To Reproduce
- Setup a postgres app
- Create a simple User table and model
- Run the query
User.objects.get(foo=bar)
Expected behavior Data is returned as expected
Screenshots
If applicable, add screenshots to help explain your problem.
Versions (please complete the following information):
- Database backend used (mysql/sqlite/postgress) postgres 12.6
- Python version 3.9.2
ormar
version 0.10.0pydantic
version 1.8- if applicable
fastapi
version 0.63.0
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
@aliakhtar right now - no.
The easiest way to get this issue away is change the tablename to non reserved sql keyword (as this is the source of the error), i.e. ‘users’ instead of ‘user’.
Fixed in 0.10.1