Optimizing a query
I currently have the following code to update the pricing of the items in the database:
This is a cron job that runs every day and I have 700 items. So every day, 700 queries are being executed.
This is not great, especially since I'm using Accelerate as this costs 21000 queries a month (700 * 30).
I don't know how to optimize this, since updateMany doesn't work with multiple different id's.
Any help would be great!
2 Replies
Hey 👋
We have a related GitHub Feature request here:
https://github.com/prisma/prisma/issues/8238
One another approach would be to use raw sql queries.
Have you seen this related solution posted by a user?
https://github.com/prisma/prisma/discussions/19765#discussioncomment-8244861
GitHub
Update multiple rows at one time · Issue #8238 · prisma/prisma
Problem There seems no way to update many rows by one call. Suggested solution Implement a method that to update multiple rows by one call. For example) You wanna make a query like below. UPDATE TO...
GitHub
Update multiple rows without looping through · prisma prisma · Disc...
This question has been asked before, see here: #12389 But I think it's worth bringing it up again. EDIT: In a hindsight, I should probably have just continued in the previous discussion. I as a...
Thank you! I used the SQL approach and it works perfect! I hope Prisma will support this natively
Coming back to this.
I use Supabase as my database which uses PostgreSQL. I also have a local Supabase docker instance for development.
Locally, my Prisma raw sql query runs fine, but in production (Vercel) I'm getting the following error message:
+server.ts
:
bulkUpdates.ts
:
What am I doing wrong?
Update:
I tried to run the generated SQL directly in Supabase's SQL Editor, no errors!
What is going wrong that I get the PrismaClientKnownRequestError
only in production?