Skip to content

[BUG]: toSQL does not convert column names #4919

@DallasHoff

Description

@DallasHoff

Report hasn't been filed before.

  • I have verified that the bug I'm about to report hasn't been filed before.

What version of drizzle-orm are you using?

0.44.2

What version of drizzle-kit are you using?

N/A

Other packages

No response

Describe the Bug

The SQL string returned from the toSQL method does not match the return type of the query. Column aliases from the schema or defined in SELECT and RETURNING clauses are ignored. Examples:

const prices = sqliteTable('prices', {
  id: int('id').primaryKey({ autoIncrement: true }),
  productId: int('item_id').notNull(),
  price: real('price').notNull(),
});

// Aliases from the schema are not processed

const inferred1 = db.select().from(prices)['_']['result'];
// type: { id: number; productId: number; price: number; }[]

const sql1 = db.select().from(prices).toSQL();
// returned: "select \"id\", \"item_id\", \"price\" from \"prices\""

// Explicit aliases are ignored too

const inferred2 = db.select({ productId: prices.productId }).from(prices)['_']['result'];
// type: { productId: number; }[]

const sql2 = db.select({ productId: prices.productId }).from(prices).toSQL();
// returned: "select \"item_id\" from \"prices\""

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions