since version 9.5 postgres offers UPSERT functionality with INSERT statement.
Say you have a table called my_table, created in several previous examples. We insert a row, returning PK value of inserted row:
b=# INSERT INTO my_table (name,contact_number) values ('one',333) RETURNING id;
id
----
...