2
votes

My code is as follows:

let assetTag = Expression<String>("asset_tag")


let query2 = mdm.select(mdm[assetTag],os, mac, lastReported)
                .filter(mdm[assetTag] != "ipad" && location == facility)
                .order(mdm[assetTag])
                .join(mdm, on: ewp[assetTag] == mdm[assetTag])



            let results2 = try! db.prepare(query2)

I am getting error that says:

fatal error: 'try!' expression unexpectedly raised an error: ambiguous column name: mdm.asset_tag (code: 1): file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-802.0.53/src/swift/stdlib/public/core/ErrorType.swift, line 182

My database has two tables, one called eWP and one called MDM. Both do have a column called asset_tag so I thought by doing mdm[assetTag] that would select the correct one but it still throws the error.

EDIT

Still unable to resolve issue. I create my tables as follows:

let db = try Connection("\(path)/db.sqlite3")

        try db.run(ewp.create { t in
            t.column(assetTag)
            t.column(location)
            t.column(deviceStatus)

        })

        try db.run(mdm.create { t in
            t.column(assetTag)
            t.column(os)
            t.column(mac)
            t.column(lastReported)

        })

    }

For some reason, mdm[assetTag] is still saying the column is ambiguous but theres only 1 column like that.

1

1 Answers

3
votes

Found the answer. I was joining the mdm table on itself. I needed to change the join to:

.join(ewp, on: ewp[assetTag] == mdm[assetTag])