Is there a way to merge a `jsonb` column when upse...
# help
a
Is there a way to merge a
jsonb
column when upserting with Supabase? For example if I have a table on Postgres with a
jsonb
column containing
{"a": 1, "b": 2}
and I want to upsert a record with the same id and
{"b": 10, "c": 20}
as the
jsonb
column value. Without Supabase this looks like
Copy code
sql
insert into the_table (id, json_column)
values (1, '{"b": 10, "c": 20}'::jsonb)
on conflict (id) do update
   set json_column = table_name.json_column || excluded.json_column;
With Supabase it doesn't seem you can provide do something like
Copy code
typescript
await supabase
  .from('the_table')
  .upsert({ id: 1, json_column: {"b": 10, "c": 20} }, { onConflict: 'json_column <something here?>' })
n
Hello @Amos! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
PostgREST is the underlying API interface if you ever need to see details of what can be done thru clients/API. For what you want to do, probably an RPC function is only way, but I'm just glancing.
n
Amos (2022-05-16)