0

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

RP1
  • 275
  • 1
  • 3
  • 14
  • https://stackoverflow.com/q/26703476/495157 – JGFMK Feb 04 '20 at 05:44
  • @JGFMK I already went through that post but it didn’t resolve my issue. It will be helpful if someone could share a sample query for the above example. – RP1 Feb 04 '20 at 05:57

0 Answers0