- changed status to resolved
add standalone distinct() in addition to existing col.distinct()
I'm using SQLAlchemy 0.3.6 with a MySQL 5 database. I want to create a query like the following:
SELECT COUNT(DISTINCT column1, column2) FROM table;
The problem is, when using
select( [ func.count( Table.c.column1, Table.c.column2) ], distinct = True).execute()
SQLAlchemy creates:
SELECT DISTINCT count(table.column1, table.column2) FROM table
when I really wanted
SELECT count(DISTINCT table.column1, table.column2) FROM table
Can there be a workaround for this special case or is it already possible, but I didn't find it?
I'm currently using the following as a workaround:
select( [ func.count( func.distinct( func.concat( Table.c.column1, Table.c.column2))) ]).execute().scalar()
which works out as something like:
SELECT COUNT(DISTINCT(CONCAT( column1, column))) FROM table;
Bug, feature, notabug?
Thanks!
Comments (5)
-
repo owner -
repo owner - removed status
- changed component to sql
- changed title to add standalone distinct() in addition to existing col.distinct()
- changed milestone to 0.4.0
- marked as enhancement
- changed status to open
however, might be nice to add
distinct()
as a standalone. -
Account Deleted Thanks, the above code works indeed :)
-
repo owner - changed status to resolved
-
repo owner - removed milestone
Removing milestone: 0.4.0 (automated comment)
- Log in to comment
i believe you can say:
reopen the ticket if that doesnt work.