In GRDB 4.14.0, I have an index that effectively treats NULL as a unique value.
try db.execute(sql: """
CREATE UNIQUE INDEX IF NOT EXISTS
'idx_labor_hours' ON 'laborHours' (
date,
ifnull(jobGuid, '\(emptyGuid)'),
ifnull(foremanGuid, '\(emptyGuid)'),
ifnull(costCodeGuid, '\(emptyGuid)')
) WHERE isDeleted=0
""")
Perhaps I'm misunderstanding, but based on what I read from SQLite's Indexes On Expressions page, this should be valid, since deterministic functions are allowed in the indexed-column portion of the statement.
In GRDB 4.14.0, this index works as I expected. For example, if a row "2020-09-25, guid A, NULL, NULL" exists in the database, then I cannot create another row "2020-09-25, guid A, NULL, NULL".
After updating to to GRDB 5.0.0, queries against the table with this index cause a fatal error Fatal error: could not convert database value NULL to String (column: 'name', column index: 2, row: [seqno:1 cid:-2 name:NULL])
in public func indexes(on tableName: String) throws -> [IndexInfo] in Database+Schema.swift (line 204), while attempting to determine a column name on the index.
I'm guessing that because the index uses a function, there is no column name, hence the NULL value. In GRDB 4.14.0, this function does not appear to be called (my breakpoints were not hit; the pod was compiled with no optimizations), which might be how it was working previously? Is there a way to give a name to the function portions (aliasing with AS does not appear to be valid)?
GRDB flavor(s): GRDB, GRDBCombine when running GRDB 4.14.0 (might not factor in here)
GRDB version: 4.14.0 -> 5.0.0
Installation method: CocoaPods for 4.14.0, Swift Package Manager for 5.0.0
Xcode version: 12.0
Swift version: 5
Platform(s) running GRDB: iOS 14
macOS version running Xcode: 10.15.7
If needed, I can work on getting a demo project put together.
Hello @wyattbeavers, thanks for reporting this issue. You did nothing wrong: this is a plain and simple regression which needs to be fixed!
Fixed in in v5.0.1!
Fixed in in v5.0.1!
Thank you!
Most helpful comment
Fixed in in v5.0.1!