drizzle-team/drizzle-orm · error · Error

Unexpected state: no column name for index ${index} found in

Error message

Unexpected state: no column name for index ${index} found in the column metadata. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose

What it means

A column-metadata entry exists for `index` but its `name` property is missing. drizzle needs the column name to build the row object in array mode, so it treats an unnamed metadata entry as an internal bug and asks the user to report it.

Source

Thrown at drizzle-orm/src/aws-data-api/pg/session.ts:86

		const { fields, joinsNotNullableMap, customResultMapper } = this;

		const result = await this.values(placeholderValues);
		if (!fields && !customResultMapper) {
			const { columnMetadata, rows } = result;
			if (!columnMetadata) {
				return result;
			}
			const mappedRows = rows.map((sourceRow) => {
				const row: Record<string, unknown> = {};
				for (const [index, value] of sourceRow.entries()) {
					const metadata = columnMetadata[index];
					if (!metadata) {
						throw new Error(
							`Unexpected state: no column metadata found for index ${index}. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`,
						);
					}
					if (!metadata.name) {
						throw new Error(
							`Unexpected state: no column name for index ${index} found in the column metadata. Please report this issue on GitHub: https://github.com/drizzle-team/drizzle-orm/issues/new/choose`,
						);
					}
					row[metadata.name] = value;
				}
				return row;
			});
			return Object.assign(result, { rows: mappedRows });
		}

		return customResultMapper
			? customResultMapper(result.rows!)
			: result.rows!.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));
	}

	async all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']> {
		const result = await this.execute(placeholderValues);
		if (!this.fields && !this.customResultMapper) {

View on GitHub (pinned to b7862528fd)

Solutions

  1. Alias every computed/expression column (`select some_func() as fn_result`).
  2. Avoid array-mode execution for queries with unaliased expressions; use the typed select builder.
  3. If it reproduces with a simple query, report it as instructed.

Example fix

// before
await db.execute(sql`select count(*) from t`);
// after
await db.execute(sql`select count(*) as cnt from t`);
Defensive patterns

Strategy: validation

Validate before calling

// Alias every expression column in raw SQL sent to the Data API
import { sql } from 'drizzle-orm';
const safe = await db.execute(sql`select count(*) as cnt from t`);

Type guard

import type { ColumnMetadata } from '@aws-sdk/client-rds-data';
function allMetadataNamed(meta: ColumnMetadata[] | undefined): boolean {
  return Array.isArray(meta) && meta.every((m) => !!m.name);
}

Try / catch

try {
  rows = await db.execute(sql`select count(*) from t`);
} catch (e) {
  if ((e as Error).message.includes('no column name for index')) {
    rows = await db.execute(sql`select count(*) as cnt from t`);
  } else throw e;
}

Prevention

When it happens

Trigger: The RDS Data API returned `columnMetadata[i]` without a `name` — e.g. for an expression column without an alias, or for a column the API could not name. Happens when selecting unaliased function calls through the pg AWS Data API driver in array mode.

Common situations: Selecting `some_func()` without an alias, or computed columns the Data API does not name.

Related errors


AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03). Data as JSON: /data/errors/3e82f70ed456afc6.json. Report an issue: GitHub.