public function getLastInsertId()
    {
        $connection = $this->getConnection();
        $id = $connection->lastInsertId();
        if ($id < 1) {
            $fullTableName = $this->tableName;
            $fullUniqueIdName = $connection->quoteIdentifier($this->getUniqueId());
            $sql = /** @lang PostgreSQL */
                "SELECT $fullUniqueIdName 
                 FROM $fullTableName
                 LIMIT 1 
                 OFFSET (SELECT count($fullUniqueIdName)-1 FROM $fullTableName )";

            $id = $connection->fetchColumn($sql);
        }
        return $id;
    }