drizzle-team/drizzle-orm · error · Error
Set operator error (union / intersect / except): selected fi
Error message
Set operator error (union / intersect / except): selected fields are not the same or are in a different order
What it means
Error "Set operator error (union / intersect / except): selected fields are not the same or are in a different order" thrown in drizzle-team/drizzle-orm.
Source
Thrown at drizzle-orm/src/gel-core/query-builders/select.ts:516
rightSelection:
| ((setOperators: GetGelSetOperators) => SetOperatorRightSelect<TValue, TResult>)
| SetOperatorRightSelect<TValue, TResult>,
) => GelSelectWithout<
this,
TDynamic,
GelSetOperatorExcludedMethods,
true
> {
return (rightSelection) => {
const rightSelect = (typeof rightSelection === 'function'
? rightSelection(getGelSetOperators())
: rightSelection) as TypedQueryBuilder<
any,
TResult
>;
if (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {
throw new Error(
'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',
);
}
this.config.setOperators.push({ type, isAll, rightSelect });
return this as any;
};
}
/**
* Adds `union` set operator to the query.
*
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
*
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
*
* @example
*View on GitHub (pinned to b7862528fd)
Solutions
- Ensure both sides of the union/intersect/except select the same fields with the same names and in the same order.
- Use explicit column selections (not select() with different shapes) on each branch of the set operator.
When it happens
Trigger: Combining queries with union/intersect/except on Gel where the selected fields differ in name, type, or order.
Common situations: Different column subsets on each branch; different select order; extra computed field on one side only.
AI-assisted analysis of drizzle-team/drizzle-orm@b7862528fd (2026-08-03).
Data as JSON: /data/errors/88f2f0d03cd598a0.json.
Report an issue: GitHub.