Skip to content

TypeORM does not compose the correct SQL #11077

@frbuceta

Description

@frbuceta

Issue description

When using .onUpdate, the SQL is not being composed correctly.

Expected Behavior

INSERT INTO "product_category" AS "ProductCategory"("_id", "name") VALUES ($1, $2), ... ON CONFLICT ( "_id" ) DO UPDATE SET "name" = EXCLUDED."name" WHERE ("ProductCategory"."name" IS DISTINCT FROM EXCLUDED."name") RETURNING "id"

Actual Behavior

QueryFailedError: invalid reference to FROM-clause entry for table "product_category"

INSERT INTO "product_category" AS "ProductCategory"("_id", "name") VALUES ($1, $2), ... ON CONFLICT ( "_id" ) DO UPDATE SET "name" = EXCLUDED."name" WHERE ("product_category"."name" IS DISTINCT FROM EXCLUDED."name") RETURNING "id"

Steps to reproduce

await this.productCategoryRepo
    .createQueryBuilder()
    .insert()
    .values(
        categories.map((category) => ({
            _id: category.id,
            name: category.name,
        })),
    )
    .orUpdate(
        ['name'],
        ['_id'],
        {
            skipUpdateIfNoValuesChanged: true,
        }
    )
    .execute();

My Environment

Dependency Version
Operating System LINUX
Node.js version 20.17.0
Typescript version 5.6.2
TypeORM version 0.3.20

Additional Context

No response

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?

Yes, I have the time, but I don't know how to start. I would need guidance.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions