drizzle-team/drizzle-orm · error · Error

Alias "${tableName}" is already used in this query

Error message

Alias "${tableName}" is already used in this query

What it means

Error "Alias "${tableName}" is already used in this query" thrown in drizzle-team/drizzle-orm.

Source

Thrown at drizzle-orm/src/gel-core/query-builders/update.ts:375

		if (is(table, GelTable)) {
			return table[Table.Symbol.Columns];
		} else if (is(table, Subquery)) {
			return table._.selectedFields;
		}
		return table[ViewBaseConfig].selectedFields;
	}

	private createJoin<TJoinType extends JoinType>(
		joinType: TJoinType,
	): GelUpdateJoinFn<this, TDynamic, TJoinType> {
		return ((
			table: GelTable | Subquery | GelViewBase | SQL,
			on: ((updateTable: TTable, from: TFrom) => SQL | undefined) | SQL | undefined,
		) => {
			const tableName = getTableLikeName(table);

			if (typeof tableName === 'string' && this.config.joins.some((join) => join.alias === tableName)) {
				throw new Error(`Alias "${tableName}" is already used in this query`);
			}

			if (typeof on === 'function') {
				const from = this.config.from && !is(this.config.from, SQL)
					? this.getTableLikeFields(this.config.from)
					: undefined;
				on = on(
					new Proxy(
						this.config.table[Table.Symbol.Columns],
						new SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),
					) as any,
					from && new Proxy(
						from,
						new SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),
					) as any,
				);
			}

View on GitHub (pinned to b7862528fd)

Solutions

  1. Use a unique alias for each table reference in the update query via the alias() helper.
  2. Remove duplicate references to the same table alias in joins.

When it happens

Trigger: A Gel update query joins a table using an alias that is already used in the same query.

Common situations: Self-referencing update joins without alias(); duplicate alias variables in from/join clauses.


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