pg_getlastoid() can be used to retrieve the oid assigned to an inserted tuple if the result identifier is used from the last command sent via pg_exec() and was an SQL INSERT. This function will return a positive integer if there was a valid oid. It will return -1 if an error occured or the last command sent via pg_exec() was not an INSERT.