0

I have a table that looks like this:

parts
id     name       children
1      Part 1     [{id: 2, name: 'Part 2'}]
2      Part 2     []

Let's say I change the name of Part 2 to Part X

I want to update both the main data, and the nested children data.

I did this:

UPDATE parts SET name = 'Part X' WHERE id=2

Now how do I also update the JSON data to match?

I thought this was good syntax, but it's not:

UPDATE parts SET [{name: 'Part X'}] WHERE json_agg([id: 2])

Also this is Postgres v10

3

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.