Description
With casing: 'snake_case' (columns declared without an explicit DB name), ordering a set operation (union/intersect/except/…) by a column emits the JS property name in ORDER BY instead of the cased DB column name. The SELECT list is cased correctly, so ORDER BY references a column that isn't in the result set — the query fails at runtime (Postgres: column "firstName" does not exist). Affects pg (bare and asc()/desc()-wrapped) and sqlite (bare-column path). mysql/singlestore are unaffected.
Steps to reproduce
import { pgTable, text, PgDialect, QueryBuilder } from 'drizzle-orm/pg-core';
import { asc, union } from 'drizzle-orm';
const users = pgTable('users', { firstName: text() }); // no explicit db name
const dialect = new PgDialect({ casing: 'snake_case' });
const qb = new QueryBuilder(dialect);
union(qb.select().from(users), qb.select().from(users)).orderBy(asc(users.firstName));
Generated SQL:
observed: (select "first_name" from "users") union (select "first_name" from "users") order by "firstName" asc
expected: (select "first_name" from "users") union (select "first_name" from "users") order by "first_name" asc
A plain select().orderBy(asc(users.firstName)) is correct (order by "users"."first_name" asc); only set-operation ordering is affected.
Root cause
buildSetOperationQuery emits the raw column .name instead of casing.getColumnCasing(...):
drizzle-orm/src/pg-core/dialect.ts:483 (bare column) and :489 (sql-wrapped chunk)
drizzle-orm/src/sqlite-core/dialect.ts:478 (bare column)
The correct pattern is already used in mysql-core/dialect.ts:528,536, singlestore-core/dialect.ts, and sqlite-core/dialect.ts:485.
Suggested fix
Replace those three sites with this.casing.getColumnCasing(<column>) (the column object, matching mysql). After the change, all set-operation ORDER BY clauses emit "first_name", and plain selects are unchanged.
Description
With
casing: 'snake_case'(columns declared without an explicit DB name), ordering a set operation (union/intersect/except/…) by a column emits the JS property name inORDER BYinstead of the cased DB column name. The SELECT list is cased correctly, soORDER BYreferences a column that isn't in the result set — the query fails at runtime (Postgres:column "firstName" does not exist). Affects pg (bare andasc()/desc()-wrapped) and sqlite (bare-column path). mysql/singlestore are unaffected.Steps to reproduce
Generated SQL:
A plain
select().orderBy(asc(users.firstName))is correct (order by "users"."first_name" asc); only set-operation ordering is affected.Root cause
buildSetOperationQueryemits the raw column.nameinstead ofcasing.getColumnCasing(...):drizzle-orm/src/pg-core/dialect.ts:483(bare column) and:489(sql-wrapped chunk)drizzle-orm/src/sqlite-core/dialect.ts:478(bare column)The correct pattern is already used in
mysql-core/dialect.ts:528,536,singlestore-core/dialect.ts, andsqlite-core/dialect.ts:485.Suggested fix
Replace those three sites with
this.casing.getColumnCasing(<column>)(the column object, matching mysql). After the change, all set-operationORDER BYclauses emit"first_name", and plain selects are unchanged.