write a select query and take each row values and do some update or insert task postgresql 9.1, can any one give a template of function syntax for implementing such a task