{"id":"ebbf8471f4162d0f","repo":"drizzle-team/drizzle-orm","slug":"unexpected-state-no-column-metadata-found-for-ind","errorCode":null,"errorMessage":"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","messagePattern":"Unexpected state: no column metadata found for index (.+?)\\. Please report this issue on GitHub: https://github\\.com/drizzle-team/drizzle-orm/issues/new/choose","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/aws-data-api/pg/session.ts","lineNumber":81,"sourceCode":"\t\t\tincludeResultMetadata: !fields && !customResultMapper,\n\t\t});\n\t}\n\n\tasync execute(placeholderValues: Record<string, unknown> | undefined = {}): Promise<T['execute']> {\n\t\tconst { fields, joinsNotNullableMap, customResultMapper } = this;\n\n\t\tconst result = await this.values(placeholderValues);\n\t\tif (!fields && !customResultMapper) {\n\t\t\tconst { columnMetadata, rows } = result;\n\t\t\tif (!columnMetadata) {\n\t\t\t\treturn result;\n\t\t\t}\n\t\t\tconst mappedRows = rows.map((sourceRow) => {\n\t\t\t\tconst row: Record<string, unknown> = {};\n\t\t\t\tfor (const [index, value] of sourceRow.entries()) {\n\t\t\t\t\tconst metadata = columnMetadata[index];\n\t\t\t\t\tif (!metadata) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`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`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tif (!metadata.name) {\n\t\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t\t`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`,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\trow[metadata.name] = value;\n\t\t\t\t}\n\t\t\t\treturn row;\n\t\t\t});\n\t\t\treturn Object.assign(result, { rows: mappedRows });\n\t\t}\n\n\t\treturn customResultMapper\n\t\t\t? customResultMapper(result.rows!)\n\t\t\t: result.rows!.map((row) => mapResultRow(fields!, row, joinsNotNullableMap));","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/aws-data-api/pg/session.ts#L63-L99","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run the query (often transient); if reproducible, simplify the SELECT to identify the column without metadata.","Avoid selecting expressions the Data API does not describe; project explicit table columns instead.","File the issue as the message suggests, including drizzle-orm + SDK versions and the SQL."],"exampleFix":"// before\nawait db.execute(sql`select a, b, some_func() from t`);\n// after - alias and project known columns\nawait db.execute(sql`select a, b from t`);","handlingStrategy":"try-catch","validationCode":"// Avoid queries that may yield unnamed/extra columns; project explicitly\nimport { sql } from 'drizzle-orm';\nconst safe = await db.execute(sql`select a, b from t`);","typeGuard":"import type { ColumnMetadata } from '@aws-sdk/client-rds-data';\nfunction metadataMatchesWidth(meta: ColumnMetadata[] | undefined, width: number): boolean {\n  return Array.isArray(meta) && meta.length >= width;\n}","tryCatchPattern":"try {\n  rows = await db.execute(sql`select a, some_func() from t`);\n} catch (e) {\n  if ((e as Error).message.includes('no column metadata found for index')) {\n    rows = await db.execute(sql`select a, some_func() as fn_result from t`);\n  } else throw e;\n}","preventionTips":["Project explicit, named columns rather than functions/expressions.","Treat recurring occurrences as a bug and report per the message."],"tags":["drizzle-orm","aws-data-api","metadata","internal"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}