I am trying to use currVal function in postgres embedded db to get the value I have inserted in an insert statement in the same session. Please find the below code for the same.
Student Table Definition:
CREATE TABLE student (
id bigserial NOT NULL,
name varchar(255) NOT NULL,
number int8 NOT NULL,
);
CREATE TABLE student_course (
student_id foreign_key references student(id),
course_name varchar(255) NOT NULL
);
Query To Insert Student:
insert into student (name,number)
values("Student1","55");
Query to fetch id column:
insert into student_course
select currval(pg_get_serial_sequence('student','id')), 'course1';
Both the insert queries run in a single session, but I get null value when using currVal function to get the inserted id.
The same queries work fine with actual database but doesn't work in embedded extension. I am using postgis docker image for embedded db.