Open jkomyno opened 2 years ago
I think you are missing quotes around the table names. What does SELECT * FROM "Post"
return, without the @@map
?
Thank you @tomhoule. While the misleading error part of the issue still stands, I appreciate that your suggestion indeed allows to query.
Beforehand, I had also tried with SELECT FROM 'Post', SELECT FROM `Post` (with backslash escaping, hard to show here in markdown), and the equivalent version with public.
without success (also obtaining a syntax error
with error code 42601
when using single quotes. I didn't think about using double quotes.
Maybe the docs could showcase examples of how to run raw queries in different providers?
How to quote identifiers and strings in raw queries might indeed be worth documenting some way, maybe via the Dataguide.
Bug description
Querying a table/model in Postgres seems impossible, unless we explicitly set@@map("table_name")
in the Prisma schema.I wonder if it's about something that Prisma does under the hood. Consider a model
Tag
, explicitly renamed totag
via@@map
, and a modelPost
, not renamed.The following all fail with similar messages (see the snapshots in the attached TS code):
The following succeed.
Moreover, the error messages are misleading. E.g., for
SELECT * FROM Post
, it fails with an errore
where:e.message
ise.code
isP2010
(so the error code42P01
referenced above is confusing)Post
)$queryRawUnsafe
is used, not$queryRaw
(although I understand they may re-use the same code flow)How to reproduce
prisma db push
ts-node index.test.ts
(requiresjest
)Expected behavior
@@map
Raw query failed
error message should reportInvalid prisma.$queryRawUnsafe() invocation
rather thanInvalid prisma.$queryRaw() invocation
Prisma information
Environment & setup
Mac OS M1
postgres:13
18.8.0
Prisma Version