how to update records else insert records in postgresql
You can use the UPSERT:

https://www.postgresql.org/docs/9.5/static/sql-insert.html

Example from documentation: 

INSERT INTO distributors (did, dname)
VALUES (5, 'Gizmo Transglobal'), (6, 'Associated Computing, Inc')
ON CONFLICT (did) DO UPDATE SET dname = EXCLUDED.dname;