Hi there, I have a question regarding prisma.$que...
# orm-help
a
Hi there, I have a question regarding prisma.$queryRaw function. I want to call an POSTGRESQL function which take an array of string as parameter and return a boolean. So I did:
Copy code
prisma.$queryRaw<boolan>("SELECT my_function($1, $2, $3, $4)", param_1, param_2, param_3, Prisma.join(myArrayOfString));
However, this doesn't work. What is the proper way to convert my array of string into his
{"value1","value2"}
equivalent ?
j
@Ryan 👋 Interested as well, is it possible? 🙂
t
Hey @Andrew Valleteau and @Julien Goux 👋 Correct me if I'm wrong, but the more generic framing of this problem is: How do I pass an array of strings as a parameter inside a procedure/function call in
queryRaw,
correct? I would recommend using the
array[...]
notation insetad of
{...}
notation for this. So for the query you mentioned, try:
Copy code
prisma.$queryRaw<boolan>`SELECT my_function(${param_1}, ${param_2}, ${param_3}, array[${Prisma.join(myArrayOfString)}])`
Here is another example with the Postgres
array_append
function which just adds an element to the end of an array.
Copy code
let array_of_strings = [ "bar", "temp"];
    let foo = "foo"
    console.log(
        await prisma.$queryRaw<any>`SELECT array_append(ARRAY[${Prisma.join(array_of_strings)}], ${foo})`,
    ); // prints [ { array_append: [ 'bar', 'temp', 'foo' ] } ]