Postgres: Cannot Update a JSON Field
See original GitHub issueI 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:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@SamTheFam You will need to use
updateMany
here email is not unique.update
only take unique fields in where.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/