I have the following table in postgres with the below schema
Relations
| id | tags |
I need to update the field tags to append unique multiple elements to it I can very well achieve it with like the below
for (String tagId : tagIds ) {
// Execute the below query in PostGRES
UPDATE Relations SET tags = array_append (array_remove (tags, '" + tagId + "'), '" + tagId + "') WHERE id = '" + id + "'";
}
But I want to append an array of elements to it in a single go without the for loop. Can someone let me know the query for that ?
There is no simple solution.
Maybe that is an indication that you are abusing arrays and should store the tags in a table instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With