1

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

3
  • 1
    What is your Postgres version? select version(); will tell you Commented Dec 13, 2019 at 12:36
  • My current version of pgAdmin is 4.13 and postgresSql is 9.4.4. Commented Dec 23, 2019 at 6:30
  • 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 anyway Commented Dec 23, 2019 at 6:50

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

function jsonb_set(jsonb, text[], jsonb, boolean) does not exist. I am still getting this error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.