Skip to content

Swift 2.3 - Count Ignoring Distinct Collection #510

@rp4rk

Description

@rp4rk

Issue and How to Reproduce

let target = Tables.reportItemTable
            .select(distinct: Columns.reportItemTableRowNumber)
            .filter(Columns.reportItemParentReportItemInternalID == internalId)
            .count

Results in:

SELECT count(*) FROM "tblReportItem" WHERE ("ParentReportItemInternalID" = 18)

Removing the count returns a SQL statement more similar to what you would expect:

let target = Tables.reportItemTable
            .select(distinct: Columns.reportItemTableRowNumber)
            .filter(Columns.reportItemParentReportItemInternalID == internalId)

Results in:

SELECT DISTINCT "TableRowNumber" FROM "tblReportItem" WHERE ("ParentReportItemInternalID" = 17)

Temporary Workaround

The SQL statement as it should be is:

 SELECT COUNT(DISTINCT "column_name") FROM "table_name"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions