Hey everyone! I am running a raw sql query to inse...
# orm-help
b
Hey everyone! I am running a raw sql query to insert sth and it returns 400. How can I view the error messages / logs?
r
@Ba Thien Tran 👋 400 is the http query response? If so, could you check what’s the error the backend is giving and if the parameters you’re passing in the raw query are correct or not?
b
👋 Yes, sorry I should have clarified. 400 is the HTTP response after creating the raw insertion. I don’t see any response on the backend – when I log the result it is just the 400 response.
It also used to work before without any changes to the DB or the like and now its failing…
r
Could you show the code that you have written for that specific API?
b
Sure, so basically I’m inserting a relationship into a bridge table of the following format
(948, 328835),(944, 328835),(950, 328837),(945, 328837),(949, 328841),(946, 328841),(951, 328843),(947, 328843),(951, 328864),(947, 328864),(948, 328871),(944, 328871),(950, 328872),(945, 328872),(949, 328878),(946, 328878),(951, 328887),(947, 328887),(948, 328889),(944, 328889),(949, 328890),(946, 328890),(950, 328898),(945, 328898),(951, 328915)
Using
Copy code
const res = await prisma.$executeRaw(
        `INSERT INTO "public"."_DesignToImpression"
            VALUES
                ${designsValues.substring(0, designsValues.length - 1)}
            RETURNING *;`
    );
Where designsValues is the list above with an additional , at the end which i remove
r
Are the id’s numbers? If so, adding the substring wouldn’t work.
b
The entire list is a string that I concatenated before
so its not actually a list, just a long string
When I manually insert it into the DB using a different query editor it works fine
r
Yes because you’re using strings to pass the id’s while they are numbers.
b
Hm… I’m inserting a string into a template string so shouldn’t it just be the numbers then? Anyways, for some reason it is working now so I guess it resolved?
🤔 1
r
Let me know if it comes up again.
I tried this and ideally it shouldn’t work. Could you check if the values are inserted properly?
b
I have 3 similar queries where it works with the template string – the string is basically “(XXX,XXX),(XXX,XXX)” where XXX is just a number as a string