1

I have data structure like:

  • id bigint
  • articles jsonb

Example:

id: 1,
articles: {
  "1": {
    "title": "foo"
  },
  "2": {
    "title": "bar"
  }
}

I want to change field name of title (for example articleTitle). Is there any easy way to do that ?

Edit: I can do that with string replace, but can I do that operating on jsonb? Like using jsonb_set() ?

UPDATE person 
SET articles = replace(articles::TEXT,'"title":','"articleTitle":')::jsonb
3
  • Check this answer by @klin stackoverflow.com/a/42308902/1163424 Commented Apr 22, 2020 at 22:06
  • Thanks, but in this case even deeper structure with an unknown number of articles. Commented Apr 24, 2020 at 5:20
  • you'll just need to run the same query for the number of article ids you'd like to rename Commented Apr 25, 2020 at 17:11

0

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.