CurrVal function returns null in Postgres embedded db
harshilt94 opened this issue · 4 comments
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.
My guess is this is NOT related to our library but to your docker image. Run the docker image manually per docker hub instructions and test it please. If it still has the issue, report to the docker image maintainer.
Note the above was for otj-pg-embedded with a tarball. Which works totally differently and almost proves it's a PG distribution issue of some sort
Closing due to lack of response