I have a DB table with Jsonb column
number | data
1 | {name: "John", age: 31, city: "New York"}
For updating multiple keys in the same query I use the below query and it works perfectly.
UPDATE table_name
SET data = data || '{name: "John", age: 35, city: "Tokyo", active: true}'
WHERE number = 1;
But I want to pass the value dynamically to the query using a variable like below but it fails with the error Token 'v_value' is invalid.
Declare v_value jsonb;
v_value := 'true';
UPDATE table_name
SET data = data || '{name: "John", age: 35, city: "Tokyo", active: v_value}'
WHERE number = 1;
I tried couple of ways like below but nothing worked. Please help.
'{name: "John", age: 35, city: "Tokyo", active: '{v_value}'}'
'{name: "John", age: 35, city: "Tokyo", active: $'{v_value}'}'
Thanks in advance