I'm trying to run a raw query in the Prisma Query Console of the Data Platform.
The line
await prisma.$queryRaw(Prisma.sql`SELECT * FROM "public"."User";`)
Returns a PrismaClientUnknownRequestError
error with the message
$queryRaw
is a tag function, please use it like the following:
const result = await prisma.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'[email protected]'};
Or read our docs at https://www.prisma.io/docs/concepts/components/prisma-client/raw-database-access#queryraw
If instead I replace it by the following as suggested by the message
await prisma.$queryRaw`SELECT * FROM "public"."User";`
The code is greyed and the execute button is disabled so I can't run the query.
How can I run raw queries in the Query Console?
As of now (nov. 2022) this is a known limitation of the Query Console. Here is the answer from Prisma support:
The format of
$queryRaw
without parenthesis isn't supported yet, due to which the execution is disabled. The error that is returned suggests defining variables and passing them in $queryRaw in tagged literal format, as of now defining variables in Query Console isn't supported either. Our product team is aware of this limitation, and we do plan to address this.
The workaround is to use $queryRawUnsafe
. The syntax is
await prisma.$queryRawUnsafe('SELECT * FROM "public"."User"')