itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

ECSQL: Specific query fails to prepare

Open grigasp opened this issue 1 year ago • 0 comments

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:

  1. Open any iModel in iModelConsole
  2. Run the ECSQL query provided above
  3. 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]

grigasp avatar Mar 12 '24 08:03 grigasp