aitorcas
aitorcas
DTDrizzle Team
Created by peli on 10/28/2023 in #help
Column name alias
Is my first time answering here so don't fully trust me. I was able to rename a select column with the sql as() function. For example:
db.
select({
username: sql`${users.name}`.as("user_name")
})
.from(users)
db.
select({
username: sql`${users.name}`.as("user_name")
})
.from(users)
But when doing that the type of username isn't inferred, so you can add the type you want using <>.
sql<string>`${users.name}`.as("user_name")
sql<string>`${users.name}`.as("user_name")
5 replies