{"id":"88f2f0d03cd598a0","repo":"drizzle-team/drizzle-orm","slug":"set-operator-error-union-intersect-except-s","errorCode":null,"errorMessage":"Set operator error (union / intersect / except): selected fields are not the same or are in a different order","messagePattern":"Set operator error \\(union / intersect / except\\): selected fields are not the same or are in a different order","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"drizzle-orm/src/gel-core/query-builders/select.ts","lineNumber":516,"sourceCode":"\t\trightSelection:\n\t\t\t| ((setOperators: GetGelSetOperators) => SetOperatorRightSelect<TValue, TResult>)\n\t\t\t| SetOperatorRightSelect<TValue, TResult>,\n\t) => GelSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tGelSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\treturn (rightSelection) => {\n\t\t\tconst rightSelect = (typeof rightSelection === 'function'\n\t\t\t\t? rightSelection(getGelSetOperators())\n\t\t\t\t: rightSelection) as TypedQueryBuilder<\n\t\t\t\t\tany,\n\t\t\t\t\tTResult\n\t\t\t\t>;\n\n\t\t\tif (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.config.setOperators.push({ type, isAll, rightSelect });\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Adds `union` set operator to the query.\n\t *\n\t * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n\t *\n\t * @example\n\t *","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/drizzle-team/drizzle-orm/blob/b7862528fd8fc39bc2653a6c18dad7c1f4e68d10/drizzle-orm/src/gel-core/query-builders/select.ts#L498-L534","documentation":"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.","triggerScenarios":"Combining queries with union/intersect/except on Gel where the selected fields differ in name, type, or order.","commonSituations":"Different column subsets on each branch; different select order; extra computed field on one side only.","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."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"analyzedSha":"b7862528fd8fc39bc2653a6c18dad7c1f4e68d10","analyzedAt":"2026-08-03T18:11:14.318Z","schemaVersion":2}