{"record":{"id":"a734f0fa8c93169c","repo":"hasura/graphql-engine","slug":"cannot-perform-an-order-by-target-of-type-orderb","errorCode":null,"errorMessage":"Cannot perform an order by target of type ${orderByElement.target.type} on the current table. Only column-typed targets are supported.","messagePattern":"Cannot perform an order by target of type (.+?) on the current table\\. Only column-typed targets are supported\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"dc-agents/reference/src/query.ts","lineNumber":504,"sourceCode":"    );\n  }\n};\n\nconst makeGetOrderByElementValue =\n  (\n    findRelationship: (relationshipName: RelationshipName) => Relationship,\n    applyRedaction: ApplyRedaction,\n    performQuery: (targetName: TargetName, query: Query) => QueryResponse,\n  ) =>\n  (\n    orderByElement: OrderByElement,\n    row: Record<string, RawScalarValue>,\n    orderByRelations: Record<RelationshipName, OrderByRelation>,\n  ): RawScalarValue => {\n    const [relationshipName, ...remainingPath] = orderByElement.target_path;\n    if (relationshipName === undefined) {\n      if (orderByElement.target.type !== 'column')\n        throw new Error(\n          `Cannot perform an order by target of type ${orderByElement.target.type} on the current table. Only column-typed targets are supported.`,\n        );\n      return applyRedaction(\n        row,\n        orderByElement.target.redaction_expression,\n        coerceUndefinedToNull(\n          row[getColumnSelector(orderByElement.target.column)],\n        ),\n      );\n    } else {\n      const relationship = findRelationship(relationshipName);\n      const orderByRelation = orderByRelations[relationshipName];\n      const innerOrderByElement = {\n        ...orderByElement,\n        target_path: remainingPath,\n      };\n      const query = {\n        ...buildQueryForPathedOrderByElement(","sourceCodeStart":486,"sourceCodeEnd":522,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/dc-agents/reference/src/query.ts#L486-L522","documentation":"When an order-by element's target_path is empty (sort on the current table), the target must be a plain column; redaction expressions and value coercion only apply to column targets. Any other target type (aggregates, etc.) on the current row is rejected with this error.","triggerScenarios":"An order_by element with an empty target_path and target.type other than 'column' — e.g. target: { type: 'single_column_aggregate', ... } with target_path: [].","commonSituations":"Hand-constructed or programmatically generated QueryRequests that pair aggregate targets with empty paths; connector backends emitting order_by elements incorrectly.","solutions":["Give aggregate order-by targets a relationship path (non-empty target_path) so they are computed via subquery, per the engine's design.","For sorting by the row's own column, use target.type 'column' with target_path: [columnName].","Validate order_by elements before dispatch: empty path implies type 'column'."],"exampleFix":"// before\n{ target_path: [], target: { type: 'single_column_aggregate', column: 'name', function: 'max', ... }, order: 'asc' }\n\n// after\n{ target_path: ['tracks', 'name'], target: { type: 'single_column_aggregate', column: 'name', function: 'max', ... }, order: 'asc' }","handlingStrategy":"validation","validationCode":"if (orderBy.target_path.length === 0 && orderBy.target.type !== 'column')\n  throw new Error('empty order_by path requires a column target');","typeGuard":"const isColumnTarget = (t: { type: string }): t is { type: 'column'; column: string } => t.type === 'column';","tryCatchPattern":null,"preventionTips":["Pair aggregate targets with a relationship path","Use column targets for sorting on the current table"],"tags":["hasura","data-connector","order-by","unsupported-feature"],"backgroundTag":"invalid-order-by-target-path","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}