"RETURNING id" is more safe and reliable "lastval()" can cause some issues with triggers https://www.postgresql.org/docs/current/dml-returning.html https://github.com/sqlkata/querybuilder/blob/master/QueryBuilder/Compilers/PostgresCompiler.cs https://stackoverflow.com/questions/17819001/postgres-not-returning-lastval-properly https://stackoverflow.com/questions/2944297/postgresql-function-for-last-inserted-id