Skip to content

[BUG]:pgTable column renders as undefined in sql #4209

@tonyxiao

Description

@tonyxiao

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.39.1

What version of drizzle-kit are you using?

N?A

Other packages

No response

Describe the Bug

import {drizzle} from 'drizzle-orm/postgres-js'
const db = drizzle('postgres://...', {logger: true})

const t1 = pgTable('table', (t) => ({
    id: t.text().primaryKey(),
  }))

  console.log(
    t1.id.name,
    db.insert(t1).values({id: '1'}).toSQL(),
  )
  // id { sql: 'insert into "table" ("id") values ($1)', params: [ '1' ] }
  const t2 = pgTable('table', (t) => ({
    id: t.text().primaryKey(),
    name: t.text(),
  }))
  const query = db.insert(t2).values({id: '1', name: 'test'}).toSQL()
  console.log(t2.name.name, query)
  // {
  //   sql: 'insert into "table" ("id", "undefined") values ($1, $2)',
  //   params: [ '1', 'test' ]
  // }

See the repro step above. It appears that drizzle is unexpectedly caching columns based on table names, and that breaks when you construct tables dynamically

Upon some digging, I believe this is due to the unfortunate CasingCache

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions