{"record":{"id":"637035d493e16839","repo":"tursodatabase/turso","slug":"failed-to-get-column-name-at-index-i","errorCode":null,"errorMessage":"Failed to get column name at index ${i}","messagePattern":"Failed to get column name at index (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"bindings/react-native/src/Statement.ts","lineNumber":340,"sourceCode":"      if (this._execLock) {\n        this._execLock.release();\n      }\n    }\n  }\n\n  /**\n   * Read current row into an object\n   *\n   * @returns Row object with column name keys\n   */\n  private readRow(): Row {\n    const row: Row = {};\n    const columnCount = this._statement.columnCount();\n\n    for (let i = 0; i < columnCount; i++) {\n      const name = this._statement.columnName(i);\n      if (!name) {\n        throw new Error(`Failed to get column name at index ${i}`);\n      }\n\n      const value = this.readColumnValue(i);\n      row[name] = value;\n    }\n\n    return row;\n  }\n\n  /**\n   * Read value at column index\n   *\n   * @param index - Column index\n   * @returns Column value\n   */\n  private readColumnValue(index: number): SQLiteValue {\n    const kind = this._statement.rowValueKind(index);\n","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/react-native/src/Statement.ts#L322-L358","documentation":"When materializing a row, Statement.readRow() asks the native layer for each column name via columnName(i). If the call returns a falsy value (null, undefined, or an empty string), the wrapper throws rather than building a row with a broken key. In practice the native bridge either failed to produce the name or the result column genuinely has an empty name.","triggerScenarios":"stmt.get() / stmt.all() on a query whose result column has an empty alias, e.g. SELECT '' AS \"\" or a dynamically-built expression column with an empty AS clause; also a stale native binary that returns null from columnName while columnCount() reports columns.","commonSituations":"SQL built at runtime where the alias variable is an empty string; queries full of bare expressions (SELECT count(*), max(x)) after a native/JS version mismatch where the name lookup silently fails.","solutions":["Alias every expression column explicitly: SELECT count(*) AS cnt, max(x) AS max_x - never AS '' or a variable alias that can be empty","Log the SQL when the error fires and check for empty-string aliases in the SELECT list","Rebuild the native module (pod install / clean gradle) so columnName matches the JS package version","If plain named table columns still trigger it, report it as a native-bridge bug with the query"],"exampleFix":"// before\nconst rows = await db.all(`SELECT ${alias} FROM t`); // alias may be ''\n\n// after - always emit a concrete alias\nconst safeAlias = alias || 'value';\nconst rows = await db.all(`SELECT ${expr} AS ${safeAlias} FROM t`);","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { return await stmt.get(); } catch (e) { if (e instanceof Error && /Failed to get column name at index/.test(e.message)) { throw new Error(`Query produced an unnamed column - add explicit aliases: ${sql}`); } throw e; }","preventionTips":["Alias every expression column in SQL: SELECT count(*) AS cnt, max(x) AS max_x","When building SQL dynamically, never interpolate an alias variable that can be an empty string","Keep native module and JS package versions matched so columnName() never silently fails"],"tags":["react-native","column-metadata","result-mapping","sql"],"backgroundTag":"column-name-unavailable","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}