Converting SQL Server queries to PostgreSQL
Since PostgreSQL doesn't use the same traditional &quot;ID&quot; concept on Tables like SQL Server, rather it uses Sequences, getting the last value is a little different but there are a multitude of ways to do so as noticed in this well versed StackOverflow answer.
Specifically the functions you can leverage are CURRVAL and LASTVAL.
Relevant info from the aforementioned and linked StackOverflow answer:
CURRVAL():
INSERT INTO persons (lastname,firstname) VALUES ('Smith', 'John');
  SELECT currval('persons_id_seq');


The name of the sequence must be known. Caveat: currval() only works
after an INSERT (which has executed nextval() ), in the same session.

LASTVAL():

This is similar to the previous, only that you don't need to specify
the sequence name: it looks for the most recent modified sequence
(always inside your session, same caveat as above.)