Reputation: 3115
I need to generate query like this:
SELECT **DISTINCT ON** (article.code) article.code, article.title
First I try to make it via ORM distinct method and send it a list with fields. But it wont work. Second, I try to make it via sqlalchemy.sql.select - and it also generate sql query like this:
SELECT DISTINCT article.code, article.title
I Need SELECT **DISTINCT ON** (article.code)
...
I look at source code and found in sqlalchemy.dialects.postgresql.base.PGCompiler.get_select_precolumns
code for generating constructions like: 'DISTINCT ON'
But this method do not called. Instead of this called another method - sqlalchemy.sql.compiler.get_select_precolumns
- it hasn't code for generating DISTINCT ON
only for DISTINCT
Maybe I should configure my session to called properly method?
Upvotes: 4
Views: 6179
Reputation: 95532
This bug report suggests that DISTINCT ON
works correctly in SQLAlchemy 0.7+. I think an upgrade is in order, unless you've uncovered a bug in 0.7.
Workarounds . . .
DISTINCT
ON
. I'm not sure whether that's
possible in the most general case.Upvotes: 4