Updating JSON object value in column

Hello, Im trying to wrap my head around how to update a JSON column were I want to update the value not by replacing the whole object but by setting the specific field in the JSON using:
set metadata = jsonb_set(metadata, '{root,nested}', '"value"');

OR
set metadata = jsonb_set(metadata, array['root','nested'], '"value"');
set metadata = jsonb_set(metadata, '{root,nested}', '"value"');

OR
set metadata = jsonb_set(metadata, array['root','nested'], '"value"');
however im trying this and its erroring out
.updateTable('table')
.set({
metadata: sql`jsonb_set(metadata, '{root,nested}', '"${value}"');`,
})
.updateTable('table')
.set({
metadata: sql`jsonb_set(metadata, '{root,nested}', '"${value}"');`,
})
[Error] API error: PostgresError: could not determine data type of parameter $1
2 Replies
Unknown User
Unknown User4d ago
Message Not Public
Sign In & Join Server To View
koskimas
koskimas4d ago
Nothing wraps anything to ' Except sql.lit when you use a string literal The issue is that kysely doesn't interpolate strings but uses parameters when you pass values through ${some value}. In the original message '"${value}"' gets turned into '"$1"'. And the value for $1 is sent as a parameter The error message is not even from that query. It's from some other query. That's why I didn't even bother answering this originally

Did you find this page helpful?