drizzle-team/drizzle-orm · error · Error

Insert select error: selected fields are not the same or are

Error message

Insert select error: selected fields are not the same or are in a different order compared to the table definition

What it means

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.

Source

Thrown at drizzle-orm/src/gel-core/query-builders/insert.ts:125

	}

	select(selectQuery: (qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;
	select(selectQuery: (qb: QueryBuilder) => SQL): GelInsertBase<TTable, TQueryResult>;
	select(selectQuery: SQL): GelInsertBase<TTable, TQueryResult>;
	select(selectQuery: GelInsertSelectQueryBuilder<TTable>): GelInsertBase<TTable, TQueryResult>;
	select(
		selectQuery:
			| SQL
			| GelInsertSelectQueryBuilder<TTable>
			| ((qb: QueryBuilder) => GelInsertSelectQueryBuilder<TTable> | SQL),
	): GelInsertBase<TTable, TQueryResult> {
		const select = typeof selectQuery === 'function' ? selectQuery(new QueryBuilder()) : selectQuery;

		if (
			!is(select, SQL)
			&& !haveSameKeys(this.table[Columns], select._.selectedFields)
		) {
			throw new Error(
				'Insert select error: selected fields are not the same or are in a different order compared to the table definition',
			);
		}

		return new GelInsertBase(this.table, select, this.session, this.dialect, this.withList, true);
	}
}

export type GelInsertWithout<T extends AnyGelInsert, TDynamic extends boolean, K extends keyof T & string> =
	TDynamic extends true ? T
		: Omit<
			GelInsertBase<
				T['_']['table'],
				T['_']['queryResult'],
				T['_']['returning'],
				TDynamic,
				T['_']['excludedMethods'] | K
			>,

View on GitHub (pinned to b7862528fd)

Solutions

  1. Make the select passed to .select() in the insert return exactly the table's columns, in the same order as the table definition.
  2. Reorder or add/remove selected fields so they match the table schema one-to-one.

When it happens

Trigger: Using insert().select() on Gel where the select's fields don't match the table's column set or order.

Common situations: Selecting a subset/reordered set of columns; selecting from a differently shaped table; aliasing that changes field order.


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