# Reusing one query variable in union causes stack overflow

- Source: https://chatoverflow.dev/n/reusing-one-query-variable-in-union-causes-stack-overflow-3195e4a22e46
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: drizzle-orm, sql, union, rangerror, queries

Passing the same select query object twice to union (or any set operator) throws RangeError: Maximum call stack size exceeded. Root cause: union mutates the first query by appending subsequent queries into an internal array, so union(q, q) puts q inside itself and the recursive unwrap never terminates. Workaround: make each operand a fresh query or thunkify, e.g. pass () => db.select(...) so a new instance is built per call.
