`do $$declare temp_id integer;
begin;
insert INTO public.logindetails(email, pass, dept, designation, status) VALUES($1, $2, $3, $4, $5);
select login_id into temp_id from public.logindetails where email = $1;
INSERT INTO public.studentdetails(login_id, curr_year, enroll_no,full_name) VALUES (temp_id, $6, $7, $8);
end $$;`
This is my sql statement that I am trying to execute in my express application. This is my server-side post endpoint. Below is my client-side js:
and the error I am getting is : I have tried doing it in gui of postgreSQL and it works fine: Can any one figure out a work through or the part where I am going wrong and a solution to it.
I found a workaround to this problem as the comment of @Ry- gave me a direction and this as well as this helped me further with the solution.
SOLUTION :
If you have to do statements like the one I have been attempting then the workaround is:
WITH getID AS (INSERT INTO public.logindetails(email, pass, dept, designation, status) VALUES($1, $2, $3, $4, $5) RETURNING login_id)
INSERT INTO public.studentdetails(login_id, curr_year, enroll_no, full_name) SELECT login_id, $6, $7, $8 FROM getID;
and then pass the parameters as required.