Saturday, November 19, 2011

PostgreSQL Integer Array - Inserting Values to Array Fields


 Inserting values to Integer Array:


INSERT INTO post_files(id,file_ids,file_path_ids,post) 
values(1,ARRAY[1,2,3,4]::INT[],
ARRAY[1,2,3,4]::INT[],'This is new');


Like this way we have to insert the integer array values to the table.


Updating the Integer Array values:


UPDATE post_files SET 
file_ids = ARRAY(SELECT id FROM files WHERE post_id = 1) 
WHERE id = 1;


Like this way we have to update the Integer Array fields.


One Important:
While Inserting or Updating Integer Array fields, the values 
should not contains NULL values. If it has Null values it 
will produce error while doing array operations. 

No comments:

Post a Comment