0
`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.

OMKAR AGRAWAL
  • 128
  • 1
  • 9
  • 1
    What's the implementation of `hash`? That password hashing looks suspicious. Anyway, it's the `DO`. Can't parameterize those. Use `INSERT … RETURNING` to avoid the `SELECT`. – Ry- May 13 '18 at 08:56
  • @Ry- why does this hashing looks suspicious? 2) Thank you I found a solution : `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;` if you have even better solution then please provide me the better solution. – OMKAR AGRAWAL May 13 '18 at 19:55
  • 1
    Glad you found a solution! Re: the hashing: the salt is way too big. Did you mean 128 bits instead of 128 bytes? – Ry- May 13 '18 at 22:04
  • Yes I did mean 128 bits is it considering as bytes? because the person who told me to use pbkdfsync told me that it takes bits. – OMKAR AGRAWAL May 14 '18 at 19:02
  • 1
    Yep, it takes a byte count. – Ry- May 14 '18 at 23:38

1 Answers1

0

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.

OMKAR AGRAWAL
  • 128
  • 1
  • 9