itwinjs-core
itwinjs-core copied to clipboard
ECSQL: Specific query fails to prepare
Describe the bug
The following ECSQL query fails to prepare:
WITH FilteringInfo(ECInstanceId, FilteredChildrenPaths) AS (
VALUES (0x13, '[]')
)
SELECT [q].*
FROM (
SELECT childModel.*
FROM (
SELECT
ec_ClassName(model.ECClassId) AS FullClassName,
model.ECInstanceId AS ECInstanceId
FROM BisCore.GeometricModel3d model
) childModel
JOIN BisCore.GeometricModel3d this ON this.ECInstanceId = childModel.ECInstanceId
) [q]
JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]
with an error BE_SQLITE_ERROR ambiguous column name: ECInstanceId.
To Reproduce Steps to reproduce the behavior:
- Open any iModel in iModelConsole
- Run the ECSQL query provided above
- See the error
Expected behavior
The query is prepared and executed successfully
Desktop:
- iTwin.js Version: 4.4.x
Additional context
-
The given query is simplified version of a much larger query - it's not expected to make much sense in this form.
-
This workaround seems to solve the issue:
WITH FilteringInfo(ECInstanceId, FilteredChildrenPaths) AS (
VALUES (0x13, '[]')
)
SELECT [q].*
FROM (
SELECT childModel.ECInstanceId AS ECInstanceId, childModel.*
FROM (
SELECT
ec_ClassName(model.ECClassId) AS FullClassName,
model.ECInstanceId AS ECInstanceId
FROM BisCore.GeometricModel3d model
) childModel
JOIN BisCore.GeometricModel3d this ON this.ECInstanceId = childModel.ECInstanceId
) [q]
JOIN FilteringInfo [f] ON [f].[ECInstanceId] = [q].[ECInstanceId]