{"id":"011af67807e5dedd","repo":"drizzle-team/drizzle-orm","slug":"insert-select-error-selected-fields-are-not-the-s","errorCode":null,"errorMessage":"Insert select error: selected fields are not the same or are in a different order compared to the table definition","messagePattern":"Insert select error: selected fields are not the same or are in a different order compared to the table definition","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/gel-core/query-builders/insert.ts","lineNumber":125,"sourceCode":"\t}\n\n\tselect(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;\n\tselect(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;\n\tselect(\n\t\tselectQuery:\n\t\t\t| SQL\n\t\t\t| GelInsertSelectQueryBuilder<TTable>\n\t\t\t| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),\n\t): GelInsertBase<TTable, TQueryResult> {\n\t\tconst select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;\n\n\t\tif (\n\t\t\t!is(select, SQL)\n\t\t\t&& !haveSameKeys(this.table[Columns], select._.selectedFields)\n\t\t) {\n\t\t\tthrow new Error(\n\t\t\t\t'Insert select error: selected fields are not the same or are in a different order compared to the table definition',\n\t\t\t);\n\t\t}\n\n\t\treturn new GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);\n\t}\n}\n\nexport type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =\n\tTDynamic extends true ? T\n\t\t: Omit<\n\t\t\tGelInsertBase<\n\t\t\t\tT['_']['table'],\n\t\t\t\tT['_']['queryResult'],\n\t\t\t\tT['_']['returning'],\n\t\t\t\tTDynamic,\n\t\t\t\tT['_']['excludedMethods'] | K\n\t\t\t>,","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/gel-core/query-builders/insert.ts#L107-L143","documentation":"Error \"Insert select error: selected fields are not the same or are in a different order compared to the table definition\" thrown in drizzle-team/drizzle-orm.","triggerScenarios":"Using insert().select() on Gel where the select's fields don't match the table's column set or order.","commonSituations":"Selecting a subset/reordered set of columns; selecting from a differently shaped table; aliasing that changes field order.","solutions":["Make the select passed to .select() in the insert return exactly the table's columns, in the same order as the table definition.","Reorder or add/remove selected fields so they match the table schema one-to-one."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}