Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upsert with generated columns #10889

Open
1 of 18 tasks
christianblais opened this issue May 13, 2024 · 0 comments
Open
1 of 18 tasks

Upsert with generated columns #10889

christianblais opened this issue May 13, 2024 · 0 comments

Comments

@christianblais
Copy link

christianblais commented May 13, 2024

Issue description

Upsert does not respect the update: false option of generated columns (or maybe all columns?).

Expected Behavior

I have this generated column;

  @Column({
    type: 'boolean',
    generatedType: 'STORED',
    update: false,
    insert: false,
    asExpression: `keepalive IS NOT NULL`,
    nullable: false,
  })
  inProgress: boolean;

I'm trying to upsert a record using the following code;

await Record.getRepository().upsert({ foo: 1, bar: 2 }}, ['foo', 'bar', 'inProgress']);

Even though inProgress is used as part of the ON CONFLICT clause, I wouldn't expect it to be updated. Yet, I get this error.

Error [QueryFailedError]: column "in_progress" can only be updated to DEFAULT
      at PostgresQueryRunner.query (/Users/christianblais/Code/github.com/unitoio/sync-services/services/scanner-worker/node_modules/typeorm/driver/src/driver/postgres/PostgresQueryRunner.ts:331:19)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at InsertQueryBuilder.execute (/Users/christianblais/Code/github.com/unitoio/sync-services/services/scanner-worker/node_modules/typeorm/query-builder/src/query-builder/InsertQueryBuilder.ts:163:33)
      [...]
      at async Test.run (node:internal/test_runner/test:632:9)
      at async Suite.processPendingSubtests (node:internal/test_runner/test:374:7) {
    query: 'INSERT INTO "public"."table"("foo", "bar" VALUES ($1, $2) ON CONFLICT ( "foo", "bar", "in_progress" ) DO UPDATE SET "foo" = EXCLUDED."foo", "bar" = EXCLUDED."bar", "in_progress" = EXCLUDED."in_progress", "keepalive" = EXCLUDED."keepalive"  RETURNING "foo", "bar", "keepalive", "in_progress"',
    parameters: [ '1', '2'],
    driverError: error: column "in_progress" can only be updated to DEFAULT

As you can see, the DO UPDATE SET still tries to update the generated column, even though it is 1) generated and 2) flagged as update: false.

Actual Behavior

I would have expected the DO UPDATE SET to not include generated columns, nor any other column with update: false.

Steps to reproduce

I don't have reproducible steps at hand.

My Environment

Dependency Version
Operating System
Node.js version 20.11.1
Typescript version 5.4
TypeORM version 0.3.20

Additional Context

No additional context.

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 and I’m okay to wait for the community / maintainers to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant