Odd error when querying on a unique index


I'm querying the database on a unique index:

extension DerivableRequest where RowDecoder == Aperture {
    func identicalAperture(as aperture: Aperture) -> Self {
        filter(key: ["code": aperture.code,
                     <a whole list>
                     "flashText": aperture.flashText])

I get the following error when GRDB tries to make it into a query: Fatal error: could not convert database value NULL to String (column: name, column index: 2, row: [seqno:0 cid:-2 name:NULL])

All properties of the type are optionals, and many of them are in fact nil during the query.

The unique index is created as follows:

try db.execute(sql: "CREATE UNIQUE INDEX \"uniqueAperture\" ON \"aperture\"
    (IFNULL(code,255) AS code, <a whole list of IFNULL()>,

I could not find a GRDB way of creating this unique index and I have a feeling that the IFNULL() calls are the problem here.

How can I make this query work?

Thanks in advance.

Kind regards,

Remco Poelstra

I also get the same error when I construct the query from a bunch of .filter() calls, one for each column.

Hello! I think you're facing https://github.com/groue/GRDB.swift/issues/840

The fix will ship very soon..

I'm sorry, I forgot to check the GitHub issues. Again....
Thanks for fixing this quickly!

Fixed in version 5.0.1

Terms of Service

Privacy Policy

Cookie Policy