tursodatabase/turso · error · Error

Failed to get column name at index

Error message

Failed to get column name at index ${i}

What it means

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.

Solutions

  1. Alias every expression column explicitly: SELECT count(*) AS cnt, max(x) AS max_x - never AS '' or a variable alias that can be empty
  2. Log the SQL when the error fires and check for empty-string aliases in the SELECT list
  3. Rebuild the native module (pod install / clean gradle) so columnName matches the JS package version
  4. If plain named table columns still trigger it, report it as a native-bridge bug with the query

Example fix

// before
const rows = await db.all(`SELECT ${alias} FROM t`); // alias may be ''

// after - always emit a concrete alias
const safeAlias = alias || 'value';
const rows = await db.all(`SELECT ${expr} AS ${safeAlias} FROM t`);
Defensive patterns

Strategy: try-catch

Try / catch

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; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of tursodatabase/turso@244cde92a7 (2026-08-20). Data as JSON: /api/errors/637035d493e16839. Report an issue: GitHub.

Appendix: source

Thrown at bindings/react-native/src/Statement.ts:340

      if (this._execLock) {
        this._execLock.release();
      }
    }
  }

  /**
   * Read current row into an object
   *
   * @returns Row object with column name keys
   */
  private readRow(): Row {
    const row: Row = {};
    const columnCount = this._statement.columnCount();

    for (let i = 0; i < columnCount; i++) {
      const name = this._statement.columnName(i);
      if (!name) {
        throw new Error(`Failed to get column name at index ${i}`);
      }

      const value = this.readColumnValue(i);
      row[name] = value;
    }

    return row;
  }

  /**
   * Read value at column index
   *
   * @param index - Column index
   * @returns Column value
   */
  private readColumnValue(index: number): SQLiteValue {
    const kind = this._statement.rowValueKind(index);

View on GitHub (pinned to 244cde92a7)