JSON column updates don't work
See original GitHub issueBug report
Describe the bug
It doesn’t appear possible to update JSON columns.
To Reproduce
const { data, error } = await this.supabase
.from('my_table')
.update({ json_col: { test: 10 } })
.eq('uid', this.user.id)
if (error) {
console.error(error)
} else if (data) {
console.info(data)
}
Expected behavior
The JSON column will be updated with the new value.
This line is returned as an error:
PATCH https://<url>/rest/v1/<table>?uid=<uid> 404
And an empty error message is returned on the next line.
I’ve not been able to find the source of the issue but it seems that something is getting lost in translation in the process of wrapping the queries and parameters in nested layers of JSON?
I’ve tried a variety of approaches but none seem to work. e.g.
// something similar to the docs page
.update(`{ json_col: { test: 10 } }`)
// else
.update({ json_col: JSON.stringify({ test: 10 }) })
// etc...
I suppose a workaround would be to just use a TEXT column and stringify the data, but thought I’d check in case there is a workable approach to use JSON columns?
System information
- OS: macOS
- Version of supabase-js: 1.29.1
- Version of Node.js: 17.3.0
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Updating JSON Columns is not working as expected #15433
Try to update a json field that has null value. Not Including all json->property in Model's fillable array.
Read more >Updates to JSON field don't persist to DB - Stack Overflow
I am using Postgres 10.3 and SQLAlchemy 1.2.8 with a column that looks like data = Column(MutableDict.as_mutable(JSON)) and I still had to do ......
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 >12 Updating a JSON Document with JSON Merge Patch
JSON Merge Patch is suitable for updating JSON documents that primarily use objects for their structure and do not make use of explicit...
Read more >Update specified data in PostgreSQL/ JSON based on 2 ...
I tried something like this, but obviously the second where clause doesn't work. UPDATE my_users SET json_workouts = JSONB_SET(json_workouts,'{ ...
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 Free
Top 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
This is how I’ve formatted the
UPDATE
RLS:Thanks for the hint on returning minimal.
EDIT: To confirm the issue is resolved when using
{ returning: 'minimal' }
without needing to addSELECT
RLSI see that update also has the option: returning minimal If you set that then it won’t do a separate select. I missed that update had that option also.