When NSDictionaryResultType is used on a fetch request and a selected column is present on a joined table, an "ambiguous column name: columnName" error results. The columns should be prefixed with tableName.columnName to avoid this ambiguity.
I experienced this error EncryptedStoreErrorMessage = "ambiguous column name: serverId" with a fetch request on User with the predicate unit.domainLeft >= 11 AND unit.domainRight <= 16, where User.unit -> OrgUnit and both User and OrgUnit have serverId columns.
The SQL query generated by ECD:
SELECT DISTINCT serverId, localId FROM ecdUser
LEFT OUTER JOIN ecdOrgUnit AS [unit] ON ecdUser.unit__objectid = [unit].__objectID
WHERE ([unit].domainLeft >= ? AND [unit].domainRight <= ?);
And the SQL query generated by the default NSSQLiteStoreType:
SELECT t0.ZSERVERID, t0.ZLOCALID FROM ZUSER t0
JOIN ZORGUNIT t1 ON t0.ZUNIT = t1.Z_PK
WHERE ( t1.ZDOMAINLEFT >= ? AND t1.ZDOMAINRIGHT <= ?)
With these changes, the ECD query is now:
SELECT DISTINCT ecdUser.serverId, ecdUser.localId FROM ecdUser
LEFT OUTER JOIN ecdOrgUnit AS [unit] ON ecdUser.unit__objectid = [unit].__objectID
WHERE ([unit].domainLeft >= ? AND [unit].domainRight <= ?);
When
NSDictionaryResultType
is used on a fetch request and a selected column is present on a joined table, an "ambiguous column name: columnName" error results. The columns should be prefixed with tableName.columnName to avoid this ambiguity.I experienced this error
EncryptedStoreErrorMessage = "ambiguous column name: serverId"
with a fetch request onUser
with the predicateunit.domainLeft >= 11 AND unit.domainRight <= 16
, whereUser.unit -> OrgUnit
and bothUser
andOrgUnit
haveserverId
columns.The SQL query generated by ECD:
And the SQL query generated by the default NSSQLiteStoreType:
With these changes, the ECD query is now: