I need to generate a query as follows:
SELECT **DISTINCT ON** (article.code) article.code, article.title
First I try to do this using the ORM method and send him a list with fields. But that will not work. Secondly, I am trying to do this through sqlalchemy.sql.select - and it will also generate a sql query as follows:
SELECT DISTINCT article.code, article.title
I need SELECT **DISTINCT ON** (article.code) ...
I look at the source code and found sqlalchemy.dialects.postgresql.base.PGCompiler.get_select_precolumns in the code to create constructions such as: "DISTINCT ON" But this method is not called. Instead, another method is called - sqlalchemy.sql.compiler.get_select_precolumns - it does not have code to generate DISTINCT ON only for DISTINCT Maybe I need to configure my session to the correct method?
source share