My objective is to get a primary key field automatically inserted when inserting new row in the table.
How to get a sequence going from session to session in Postg
This issue seems to be intermittent , For consistency use CTE to get inserted sequence for current session
WITH inserted AS ( INSERT INTO notifn_main (notifn_dt,stat_id) SELECT now(),22 FROM notifn RETURNING id ) SELECT id from inserted INTO tmp_id;