{"id":"3e82f70ed456afc6","repo":"drizzle-team/drizzle-orm","slug":"unexpected-state-no-column-name-for-index-index","errorCode":null,"errorMessage":"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","messagePattern":"Unexpected state: no column name for index (.+?) found in the column metadata\\. 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":86,"sourceCode":"\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));\n\t}\n\n\tasync all(placeholderValues?: Record<string, unknown> | undefined): Promise<T['all']> {\n\t\tconst result = await this.execute(placeholderValues);\n\t\tif (!this.fields && !this.customResultMapper) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/aws-data-api/pg/session.ts#L68-L104","documentation":"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.","triggerScenarios":"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.","commonSituations":"Selecting `some_func()` without an alias, or computed columns the Data API does not name.","solutions":["Alias every computed/expression column (`select some_func() as fn_result`).","Avoid array-mode execution for queries with unaliased expressions; use the typed select builder.","If it reproduces with a simple query, report it as instructed."],"exampleFix":"// before\nawait db.execute(sql`select count(*) from t`);\n// after\nawait db.execute(sql`select count(*) as cnt from t`);","handlingStrategy":"validation","validationCode":"// Alias every expression column in raw SQL sent to the Data API\nimport { sql } from 'drizzle-orm';\nconst safe = await db.execute(sql`select count(*) as cnt from t`);","typeGuard":"import type { ColumnMetadata } from '@aws-sdk/client-rds-data';\nfunction allMetadataNamed(meta: ColumnMetadata[] | undefined): boolean {\n  return Array.isArray(meta) && meta.every((m) => !!m.name);\n}","tryCatchPattern":"try {\n  rows = await db.execute(sql`select count(*) from t`);\n} catch (e) {\n  if ((e as Error).message.includes('no column name for index')) {\n    rows = await db.execute(sql`select count(*) as cnt from t`);\n  } else throw e;\n}","preventionTips":["Always alias computed columns (`fn() as alias`).","Use the typed select builder which manages names automatically."],"tags":["drizzle-orm","aws-data-api","metadata","internal"],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}