0
votes

I am trying to update jsonb value. Please tell me what I did wrong. Here I have a table that has a profile column with jsonb datatype.

UPDATE <TABLE NAME> SET
"profile" = jsonb_set('{"lastName": "dada"}'::jsonb, '{lastName}'::text[] , concat('"', (profile->'lastName'), '"')::jsonb, false)
where email = '[email protected]'

ERROR: function jsonb_set(jsonb, text[], jsonb, boolean) does not exist LINE 2: "profile" = jsonb_set('{"lastName": "dada"}'::jsonb, '{lastN... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. SQL state: 42883 Character: 44

1
What is your Postgres version? select version(); will tell youa_horse_with_no_name
My current version of pgAdmin is 4.13 and postgresSql is 9.4.4.nitesh kumar
jsonb_set was introduced in Postgres 9.5, it's not available in 9.4 - but 9.4 will be unsupported very soon, so you should plan an upgrade anywaya_horse_with_no_name

1 Answers

0
votes

Here is a correction:

UPDATE <TABLE NAME> SET
profile = jsonb_set('{"lastName": "dada"}'::jsonb, '{lastName}'::text[] , 
                      (profile->'lastName')::jsonb, false)
where email = '[email protected]'

The error was here: concat('"', (profile->'lastName'), '"')::jsonb

Mind you though, this just sets the lastname field back to the sam lastname value :-)

Best regards,
Bjarni