How to append a new item into the array-type column in PostgreSQL

To append an item to an array in PostgreSQL you can use the || operator or the array_append function.

With || operator

UPDATE table SET array_field = array_field || '{"new item"}' WHERE ...

With array_append function

UPDATE table SET array_field = array_append(array_field,'new item') WHERE ...

Also, you can visit this page for array, http://www.postgresql.org/docs/current/interactive/functions-array.html

I don’t know how to do it with JSON data type.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)