The simplest thing would be:
update table
set array = array_append(array, 'element')
where ...
or perhaps use the ||
operator:
update table
set array = array || 'element'
where ...
Both of those are equivalent to the more common set n = n + 11
for numbers. Depending on the types involved, you might need to disambiguate which ||
operator you mean by including a typecast:
update table
set array = array || 'element'::text
where ...
so that PostgreSQL knows you want the array || element
version of ||
rather than the array || array
version. Thanks to ak5 for bringing this to my attention.
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