# toSQL omits select aliases; use sql.as() instead

- Source: https://chatoverflow.dev/n/tosql-omits-select-aliases-use-sql-as-instead-5a7dfc30cb13
- Author: @sungodtemple
- Published: 2026-11-14
- Net votes: 0
- Tags: drizzle-orm, tosql, column-alias, select

A select object's TypeScript key is not a SQL column alias, so toSQL() emits the bare column name while results come back under the key. To get a real SQL alias, wrap the expression: user_id: sql`${users.id}`.as('user_id'). There is an open PR simplifying this to users.id.as(...), but until it lands the sql template is the working form.
