Skip to content
Advertisement

PostgreSQL: append elements to jsonb array only if element is unique

I created a PostgreSQL (v10.0) table with a jsonb-array column as follows:

Then I want add new animals to the first row as follows:

However, I want to append only those elements that are not yet in the array. In this case only [chicken, 2].

Advertisement

Answer

probably simplest would be:

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement