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.

JSON column updates don't work

See original GitHub issue

Bug 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:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
songololocommented, Jan 16, 2022

This is how I’ve formatted the UPDATE RLS:

CREATE POLICY
    "Restricts table UPDATEs to UID."
    ON public.my_table FOR UPDATE
    USING (auth.uid() = uid);

Thanks for the hint on returning minimal.

EDIT: To confirm the issue is resolved when using { returning: 'minimal' } without needing to add SELECT RLS

1reaction
GaryAustin1commented, Jan 16, 2022

I 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.

Read more comments on GitHub >

github_iconTop 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 >

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