add standalone distinct() in addition to existing col.distinct()

Issue #558 resolved
Former user created an issue

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)

  1. Mike Bayer repo owner

    i believe you can say:

    select(func.count([col2](col1.distinct(),)))
    

    reopen the ticket if that doesnt work.

  2. Log in to comment