William Harding
06/25/2022, 4:32 PMexecutRaw
query, passing in a list of numbers (customerIds
) (joined on ","
to create a string). I am getting this error:
Raw query failed. Code: `08P01`. Message: `db error: ERROR: insufficient data left in message`
This is the the query that does not work,
await prisma.$executeRaw`UPDATE "Customer" SET fields = fields || ${fieldUpdates} WHERE ("organizationId" = ${organizationId} AND id IN (${customerIds.join(",")}));`
It works if I hardcode the values, like this ,
await prisma.$executeRaw`UPDATE "Customer" SET fields = fields || ${fieldUpdates} WHERE ("organizationId" = ${organizationId} AND id IN (1,2,3)}));`
Console logging my list out, produces the correct results,
1,2,3
I wasn't able to find this as a bug specifically against Prisma, but wanted to check here if it is a known bug, or if there is something I'm doing obviously wrong.Richard Ward
06/25/2022, 9:38 PMqueryRaw
and executeRaw
..Richard Ward
06/25/2022, 9:38 PMBe aware that:
section of https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#executerawRichard Ward
06/25/2022, 9:39 PMconst query = Prisma.sql`UPDATE "Customer" SET fields = fields || ${fieldUpdates} WHERE ("organizationId" = ${organizationId} AND id IN (${customerIds.join(",")}));`;
await prisma.$executeRaw`${query}`;
Richard Ward
06/25/2022, 9:40 PMlet query = Prisma.sql`select min(salary) as minSalary, max(salary) as maxSalary, avg(salary) as avgSalary
from Employee`;
if (onContract) {
query = Prisma.sql`${query} where onContract = ${onContract} `;
}
const result = await prisma.$queryRaw`${query}`;
William Harding
06/25/2022, 11:32 PMWilliam Harding
06/25/2022, 11:37 PMWilliam Harding
06/26/2022, 2:13 AM= ANY
syntax instead of IN
allows it to work. The following query worked:
prisma.$executeRaw`UPDATE "Customer" SET fields = fields || ${fieldUpdates} WHERE ("organizationId" = ${organizationId} AND id = ANY (${customerIds}));`;
Ilia Kostichenko
06/27/2022, 6:04 PMIN (${Prisma.join(arrayVar)})