Skip to content

[BUG]: Types do not allow for placeholder usage in onConflictDoUpdate.set #5084

@noahw3

Description

@noahw3

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

What version of drizzle-kit are you using?

0.31.4

Other packages

No response

Describe the Bug

When creating stored procedures with placeholders, the types of set of onConflictDoUpdate do not allow placeholder values to be used.

this.insertPreparedStatement = this.db
      .insert(table)
      .values({
        id: sql.placeholder("id"),
        name: sql.placeholder("name"),
      })
      .onConflictDoUpdate({
        target: table.id,
        set: {
          // Casts necessary as `set` does not accept placeholders, even though
          // it works at runtime
          id: sql.placeholder("id") as never,
          name: sql.placeholder("name") as never,
        },
      })
      .prepare();

However, at runtime this actually does work. Turning on logging outputs the following statement:

Query: insert into "table" ("id", "name") values (?, ?) on conflict ("table"."id") do update set "id" = ?, "name" = ? -- params: <values here>

For reference, I'm attempting to do an upsert (as described in the docs) and use a prepared statement in order to bypass the SQLite statement size limit (see cloudflare/workerd#3049 (comment)). Side note for anyone else coming across this, using the drizzle prepared statement didn't resolve the issue since the parameterized query is still considered too big.

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