Arfath Tade
08/19/2021, 7:32 AMmodel Activities {
id String @id @default(uuid())
type String
minutes String
}
with data as
id | type | minutes
---------------------------
1 | running | 72
2 | walking | 92
3 | cycling | 32
I want to update minutes of id 1 and 2 in one query.
This is just a sample there can be multiple columns in the above model.
Is there a way to achieve this bulk update through one query?Ryan
08/19/2021, 7:51 AMArfath Tade
08/19/2021, 7:55 AMArfath Tade
08/22/2021, 5:30 PMawait prisma.$queryRaw`UPDATE "Activities" SET minutes = c.minutes FROM (VALUES ${values} ) AS c(id, minutes) WHERE c.id = "Activities".id;`
with below error
Raw query failed. Code: `42601`. Message: `db error: ERROR: syntax error at or near "$1"`
at cb (/home/node_modules/@prisma/client/runtime/index.js:34800:17)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
{
code: 'P2010',
clientVersion: '2.27.0',
meta: {
code: '42601',
message: 'db error: ERROR: syntax error at or near "$1"'
}
}
the same syntax is running in below example.
can you please help me to understand what went wrong?
http://sqlfiddle.com/#!17/198a3/654
Thanks!Ryan
08/23/2021, 5:50 AMjoin
as shown here?
Imported like this:
import { Prisma } from '@prisma/client'
Prisma.join
Arfath Tade
08/23/2021, 10:46 AMawait prisma.$queryRaw(`UPDATE "Activities" AS ACT SET "minutes" = c.minutes FROM (VALUES ${values} ) AS c(id, minutes) WHERE c.id = ACT.id;`);