You can do so ...
select uniq(sort(array_remove(array_cat(ARRAY[1,2,3], ARRAY[1,4,5]), NULL)))
gives:
{1,2,3,4,5}
array_remove is necessary because you cannot sort arrays using NULLS. Sorting is necessary because uniq deduplicated only if neighboring elements are found.
The advantage of this approach with respect to @Clodoaldo Neto is that it works entirely within the selection and is no exception in the FROM clause. This simplifies working with multiple columns of arrays simultaneously and in a single table scan. (Although see the Ryan Guill Version as a function in the comment).
In addition, this template works for all types of arrays (which elements are sorted).
The disadvantage is that, essentially, it is slightly slower for longer arrays (due to the sorting and distribution of 3 intermediate arrays).
I think that both this and the accept answer fail if you want to keep NULL as a result.
source share