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


im using postgresql application,

the task this

there users use app, , need maintain notification each of them based on activity lots , lots of notifications each user.

so in general put notifications in seperate table , map user id, can fetch them, im thinking use either json/array datatype, can put entire notification set array/json cell of each user row.

which 1 better, storing json or array?( im using php @ server side)

and if pick 1 among two, lets have 10 notifications, , got 11th one, how append new item array/json object in single execution(may update statement)? dont want go in basic way select row, existing array/json add new item in end(process php) , update back- here takes 2 executions change may occur , brings dataloss

so there way update query adds new element or alters existing element/node in array/json obejct types in postgresql?

to append item array in postgresql can use || operator or array_append function.

with || operator

update table set array_field = array_field || 'new item' ... 

with array_append function

update table set array_field = array_append(array_field,'new item') ... 

also can visit page array, http://www.postgresql.org/docs/current/interactive/functions-array.html

i don't know how json data type.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -