drizzle-team/drizzle-orm · error · Error

Unexpected state: no column metadata found for index ${index

Error message

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

What it means

When decoding a row in array mode, drizzle iterates `columnMetadata` by index. If `columnMetadata[index]` is undefined (fewer metadata entries than row values), this is an internal invariant violation: the RDS Data API returned a row whose width does not match its metadata. drizzle flags it as a bug to report.

Source

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

			includeResultMetadata: !fields && !customResultMapper,
		});
	}

	async execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {
		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));

View on GitHub (pinned to b7862528fd)

Solutions

  1. Re-run the query (often transient); if reproducible, simplify the SELECT to identify the column without metadata.
  2. Avoid selecting expressions the Data API does not describe; project explicit table columns instead.
  3. File the issue as the message suggests, including drizzle-orm + SDK versions and the SQL.

Example fix

// before
await db.execute(sql`select a, b, some_func() from t`);
// after - alias and project known columns
await db.execute(sql`select a, b from t`);
Defensive patterns

Strategy: try-catch

Validate before calling

// Avoid queries that may yield unnamed/extra columns; project explicitly
import { sql } from 'drizzle-orm';
const safe = await db.execute(sql`select a, b from t`);

Type guard

import type { ColumnMetadata } from '@aws-sdk/client-rds-data';
function metadataMatchesWidth(meta: ColumnMetadata[] | undefined, width: number): boolean {
  return Array.isArray(meta) && meta.length >= width;
}

Try / catch

try {
  rows = await db.execute(sql`select a, some_func() from t`);
} catch (e) {
  if ((e as Error).message.includes('no column metadata found for index')) {
    rows = await db.execute(sql`select a, some_func() as fn_result from t`);
  } else throw e;
}

Prevention

When it happens

Trigger: Executing a query through the AWS Data API pg driver where `includeResultMetadata` returned metadata with a different count than the row values — typically a transient RDS Data API inconsistency or a driver bug.

Common situations: Rare; observed with certain multi-statement or DDL-returning queries, or when RDS Data API omits metadata for computed columns. Often correlated with specific Aurora Serverless v2 quirk modes.

Related errors


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