Skip to content

.update() generating a malformed query #11629

Closed

Description

@jvdutrag

Issue description

When calling .update() passing an object.id, TypeORM is generating a malformed UPDATE query

Expected Behavior

When having something like this in your code:

const entity = await entityRepository.findOne({
  where: {
    id: 'string'
  }
})

await entityRepository.update(entity.id, {
  property: new Date()
})

TypeORM should generate a query like this:

UPDATE "entity" SET "property" = $1, "updated_at" = CURRENT_TIMESTAMP WHERE "id" = $2

Actual Behavior

But it's generating a query like this:

UPDATE "entity" SET "property" = $1, "updated_at" = CURRENT_TIMESTAMP WHERE "id" IN ($2)

Causing a malformed query and affecting other rows

Steps to reproduce

Create an entity using the following decorators as the primary key and with the specified PostgreSQL versions and TypeORM versions:

@PrimaryColumn('uuid', { generated: 'uuid', name: 'id' })
id: string

Call an update like this (same entity):

const entity = await entityRepository.findOne({
  where: {
    id: 'string'
  }
})

await entityRepository.update(entity.id, {
  property: new Date()
})

See what query was generated.

My Environment

Dependency Version
Operating System unix
Node.js version 20.3.0
Typescript version 5.0.4
TypeORM version 0.3.20

Additional Context

I am using @nestjs/[email protected] to manage dependency injection and database connection. I've injected TypeORM's data source to perform these queries.

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

No, I don’t have the time, but I can support (using donations) development.

Activity

  1. Vigneshwaran16 commented on Sep 18, 2025

    @Vigneshwaran16

    Hi @jvdutrag
    Both the queries are equivalent. Don't you think the query planner of postgres picks up which to plan use for in operator and = based on the operands.

  2. added this to the 1.0 milestone on Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions