question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Select none in update

See original GitHub issue

Problem

Currently an update is quite slow because it does 3 steps:

  1. Select my thing
  2. Update my thing
  3. Select my thing

I do understand the need for the first select to make sure it updates only one record, but the last one if a bit annoying.

Suggested solution

It was suggested elsewhere that it could be using a RETURNING/other similar clause to remove the last one. This would be nice, but my understanding is that it is an important change. I suggest as a first step to allow users to tell prisma to not return anything. This would need a new keyword in select, I suggest none:

prisma.myThing.update({
  data: { ... },
  where: { id: 1 },
  select: { none: true }
})

Alternatives

You can use an updateMany to avoid the second select.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

6reactions
mrodzcommented, Sep 18, 2022

https://www.prisma.io/docs/concepts/components/prisma-client/null-and-undefined ☝️ The docs state:

null is a value undefined means do nothing

So, you can achieve the behavior you’re looking for by writing:

prisma.myThing.update({
  data: { ... },
  where: { id: 1 },
  select: undefined
})

Hope this helps 😃

4reactions
tekohcommented, Jul 14, 2022

no updates on this? seems like its been an issue for a while now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Update field as null from a select that returns 0 rows
I am trying to update a field with a null value when the select doesn't return values. Eg: UPDATE table SET title =...
Read more >
How to UPDATE from a SELECT statement in SQL Server
UPDATE queries can change all tables' rows, or we can limit the update statement affects for certain rows with the help of the...
Read more >
How to Replace Nulls with 0s in SQL - The Data School
Null Values can be replaced in SQL by using UPDATE, SET, and WHERE to search a column in a table for nulls and...
Read more >
What is SELECT FOR UPDATE in SQL (with examples)?
SELECT FOR UPDATE is a SQL command that's useful in the context of transactional workloads. It allows you to “lock” the rows returned...
Read more >
Documentation: 15: INSERT - PostgreSQL
However, ON CONFLICT DO UPDATE also requires SELECT privilege on any ... ON CONFLICT DO NOTHING simply avoids inserting a row as its...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found