Repository navigation
Backlog
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.topic: driverAdapterstopic: postgresqltopic: typedSql
Description
Bug description
Hey there!
I've been playing around with TypedSQL and so far, it's been awesome! That being said, I'm now trying to use the Postgres driver adapter but this causes all TypedSQL queries to break.
PrismaClientKnownRequestError:
Invalid `prisma.$queryRawTyped()` invocation:
Raw query failed. Code: `42P01`. Message: `relation "MyTable" does not exist`
This is exclusive to TypedSQL queries. Typical ORM queries (prisma.myTable.findMany()) correctly make use of the schema.
Severity
Reproduction
Create a typedsql script
-- prisma/sql/myQuery.sql
SELECT * FROM "MyTable";Run prisma, call script
// File.ts
const adapter = new PrismaPg(
{ connectionString: ... },
{ schema: 'my_schema' }
);
const prisma = new PrismaClient({
adapter,
});
// Run ORM query (works fine)
console.log(await prisma.myTable.findMany({ take: 1 }));
// Run typed sql query - errors
console.log(await prisma.$queryRawTyped(myQuery()))Expected vs. Actual Behavior
Expected: Resulting TypedSQL query contains my_schema."MyTable"
Actual: Resulting TypedSQL query ignores any schema configuration
Frequency
Consistently reproducible
Does this occur in development or production?
Both development and production
Is this a regression?
Unknown
Workaround
No known workaround
Prisma Schema & Queries
N/A
Prisma Config
See repro above
Logs & Debug Info
See above
Environment & Setup
- OS: macOS
- Database: PostgreSQL
- Node.js version: 23
Prisma Version
prisma : 6.6.0
@prisma/client : 6.6.0
Computed binaryTarget : darwin-arm64
Operating System : darwin
Architecture : arm64
Node.js : v23.8.0
TypeScript : 5.8.2
Query Engine (Node-API) : libquery-engine f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine : schema-engine-cli f676762280b54cd07c770017ed3711ddde35f37a (at node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm : @prisma/prisma-schema-wasm 6.6.0-53.f676762280b54cd07c770017ed3711ddde35f37a
Default Engines Hash : f676762280b54cd07c770017ed3711ddde35f37a
Studio : 0.511.0
Preview Features : driverAdapters, metrics, typedSql
Reacted by TED Vortex (Teodor-Eugen Duțulescu), Thomas van Dam, Tamlyn Rhodes, Tobi, Marcell Toth and Adam Žingor
Metadata
Metadata
Assignees
Labels
bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.topic: driverAdapterstopic: postgresqltopic: typedSql
Activity
jacek-prisma commentedon Apr 29, 2025
Hi @theguacamoleking, the schema name parameter is not used for raw queries - when using a raw query you need to be explicit about the schema you want to use.
theguacamoleking commentedon Apr 30, 2025
Hey @jacek-prisma, thanks for taking a look.
Prisma sets the search path on connection init to a Postgres database - you can see this done here. This is definitely a regression that is introduced when switching from the built in driver to the postgres adapter.
I'm not the only one to report this issue - #24660
coreh commentedon Nov 4, 2025
I'm also hitting this on 6.18.0 with
@prisma/adapter-pgwmadden-electric commentedon Nov 20, 2026
Fixed on
v7by #29067: with aschemaoption,PrismaPgnow sets the connection'ssearch_pathto that schema (followed bypublic), so TypedSQL and raw queries with unqualified table names resolve in it.fix(adapter-pg): set search_path for custom schemas in $queryRaw (pri…
wmadden-electric commentedon Nov 24, 2026
Reopening. #29067 closed this by making the Postgres adapter set
search_pathon every connection it opens. That change broke working setups (it replaced a search path set on the role or database, and PgBouncer in its default configuration refused the connection), so it was reverted in #31190 before it reached a stable release. Raw SQL and TypedSQL therefore still ignore the adapter'sschemaoption.Until there is a fix that is safe behind connection poolers, two things work today:
SELECT * FROM "mySchema"."User".ALTER ROLE app_user SET search_path = "mySchema", public;revert(adapter-pg): stop setting search_path from the schema option (…