I am trying to convert the following SQL Server T-SQL block to a PostgreSQL compatible one using, preferably CTE or a function. The issue with converting is I am not able to figure out how I return the last inserted id (
scope_identity() in SQL Server returns the last inserted id in the identity column).
IF ( NOT EXISTS ( SELECT p_id FROM qr_request WHERE q_ota = 'Done' ) ) BEGIN INSERT INTO qr_request ( u_id ,c_id ,r_id ,q_ota ) VALUES ( 1 ,2 ,3 ,'P' ) COMMIT SELECT Scope_Identity() AS id ,p.email AS n FROM person p WHERE p.uid = 33 AND deleted = 0 END ELSE SELECT NULL AS id ,p.email AS n FROM person p WHERE p.uid = 33 AND deleted = 0
Any help would be appreciated.