I have a Java project that uses MyBatis to access a PostgreSQL database. PostgreSQL allows to return fields of a newly created row after an INSERT statement, an
You can use as follows. In xml
select NEXTVAL('base.user_id_seq')
INSERT INTO base.user(
user_id, user_name)
VALUES (#{userId}, #{userName});
In Java class from where you have called the method to insert, you can get the value by calling user.getUserId().
Basically the next val is stored inside the variable of the object. Here userId inside User.