3

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 ?

1
  • 2
    Maybe: SELECT array_cat(ARRAY['a', 'b'], ARRAY['c', 'd']) --> {a,b,c,d} Commented Feb 11, 2019 at 14:05

1 Answer 1

1

There is no simple solution.

Maybe that is an indication that you are abusing arrays and should store the tags in a table instead.

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

Comments

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.