Skip to content

distinct prefix on NSDate Expression fails #611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pumplerod opened this issue Feb 25, 2017 · 1 comment
Open

distinct prefix on NSDate Expression fails #611

pumplerod opened this issue Feb 25, 2017 · 1 comment

Comments

@pumplerod
Copy link

pumplerod commented Feb 25, 2017

More than likely I'm doing something incorrect. That being said, I am trying to work with a datetime field and extract rows by date. So, provided 100 entries over 5 days, I'd like to query for distinct days in addition to pulling out all the entries on a day by day basis.

I found reference here for how to reference the date.day portion of a datetime field, however when I try and use the 'distinct' prefix I get a "Ambiguous reference to member 'distinct'" error.

I have also posted this question to stackoverflow

There is a bit of reference to using Date in the docs however I'm not clear enough on the full implications of what's mentioned to know if the issue with the 'distinct' prefix is a bug or functioning as designed.

Hopefully someone here can point me in the right direction. Thanks in advance, and thanks for the great library.

let db = try Connection("/path/to/db.sqlite")
let logs = Table("logs")

extension Expression where Datatype: NSDate {
    var day: Expression<NSDate> {
        return Expression<NSDate>("time_entry(\(template))", bindings)
    }
}

let date = Expression<NSDate>("time_entry")
let id = Expression<Int64>("id")

/* This fails */
let count = try db.scalar(logs.select(date.distinct.count))
let count = try db.scalar(logs.select(date.day.distinct.count))

/* This succeeds (however is not very useful) */
let count = try db.scalar(logs.select(id.distinct.count))
@jberkel
Copy link
Collaborator

jberkel commented Aug 25, 2021

do you still get this error? can you post the full error message?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants