CTE query not working properly
Look at attached photo for error code and query. This query works when running against local DB, but doesn't work when running against deployed DB.
I'm able to run this query against both DBs using raw sql outside of Prisma.
I'd love some help here!
On v5.7.0
6 Replies
Are you using typedsql?
https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql
Writing Type-safe SQL with TypedSQL and Prisma Client | Prisma Docu...
Learn how to use TypedSQL to write fully type-safe SQL queries that are compatible with any SQL console and Prisma Client.
I haven't tried a CTE with it, but definitely like how this works much better than just having sql inline with your code
Does that really change anything though? It's still the same query being executed
I had plenty of issues doing it the other way, using the typed sql I was actually able to get it to work
Interesting, I'll give it a go
I tried and it didn't work 😦
hrm, lemme play with my setup a sec and see if I can replicate it
Oh, check if you can issue a query without the CTE's
Ok, did a very basic CTE and it worked. I had issues, like omfg issues, using
IN
before. Also your ?
has to be $1, $2... etc
Here's my initial test query
and code I used to call it
Also, make sure you are using npx prisma generate --sql
or it won't find your query
Ok, this query worked
This did not
work however
nor did this
And this won't even run
@Tyler Benfield @Jon Harrell I know the docs say to use ANY
for these things, but I've yet to get it to work. All I see is this kind of output
local: PostgreSQL 16.4 (Ubuntu 16.4-0ubuntu0.24.04.2) on x86_64-pc-linux-gnu, compiled by gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0, 64-bit
remote: PostgreSQL 16.4 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 13.3.1 20240522 (Red Hat 13.3.1-1), 64-bit
(Digital Ocean)
For completeness here's my db.js file
and initialization stuff in schema.prisma