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.

Postgres: Cannot Update a JSON Field

See original GitHub issue

I have a JSON in my database model like this:

email Json? @db.JsonB

But when I try and update my database like this, I get a Typescript error:

await prisma.user.update({
    data: {
        emailConfirmed: true,
    },
    where: {
        email: emailHash,
    },
});

Here is the error:

Type '{ email: EmailHash; }' is not assignable to type 'UserWhereUniqueInput'.
  Object literal may only specify known properties, and 'email' does not exist in type 'UserWhereUniqueInput'.ts(2322)

It doesn’t look like it’s possible to update JSON fields with prisma, making the JSON type almost useless.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
pantharshit00commented, May 28, 2021

@SamTheFam You will need to use updateMany here email is not unique. update only take unique fields in where.

  await prisma.user.updateMany({
    where: {
      email: {
        equals: email,
      },
    },
    data: {
      str: "some string",
    },
  });
0reactions
conaticuscommented, May 18, 2021

Ah, I think I explained it incorrectly. The issue is using where on a JSON field.

Here’s the repo: https://github.com/SamTheFam/prisma-7121/

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to perform update operations on columns of type JSONB ...
As an examples, I have this basic table structure: CREATE TABLE test(id serial, data jsonb);
Read more >
Updating JSON Data in PostgreSQL - Aaron Bos
Updating JSON Data in PostgreSQL. If you're storing JSON data in Postgres, you'll eventually need to update it. In this post, we'll talk ......
Read more >
postgresql 13 - how to update a property value of a jsonb field?
There are two ways to accomplish this: Simply concatenating the new key/value pair: update the_table set attr = attr || '{"is_default": ...
Read more >
JSON in PostgreSQL: The Ultimate Guide - Database Star
You can update a JSON field using an UPDATE statement. Using this UPDATE statement, you can add a new key and value to...
Read more >
9.6: JSON Functions and Operators - PostgreSQL
Function Return Type Example Result json_array_length(json). jsonb_array_length(jsonb) int 5 json_each_text(json). jsonb_each_text(jsonb) setof key text, value text key | value... json_object_keys(json). jsonb_object_keys(jsonb) setof text json_object_k...
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