Search code examples
node.jspostgresqlexpressplpgsqlpgpool

why does it states that my sql statement needs no parameters


`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. enter image description here This is my server-side post endpoint. Below is my client-side js: enter image description here

and the error I am getting is : enter image description here I have tried doing it in gui of postgreSQL and it works fine: enter image description here Can any one figure out a work through or the part where I am going wrong and a solution to it.

Just see if this helps: enter image description here Assistance appreciated greatly.


Solution

  • 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.