Skip to content

Schema isn't included in queries when using TypedSQL in combination with Driver Adapter #26930

Backlog

Description

@theguacamoleking

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

⚠️ Major: Breaks core functionality (e.g., migrations fail)

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

Activity

  1. added
    bug/1-unconfirmed
    on Apr 29, 2025
  2. jacek-prisma commented on Apr 29, 2025

    @jacek-prisma
    Contributor

    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.

  3. removed
    bug/1-unconfirmed
    on Apr 29, 2025
  4. theguacamoleking commented on Apr 30, 2025

    @theguacamoleking
    Author

    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

  5. added
    bug/1-unconfirmed
    on May 12, 2025
  6. coreh commented on Nov 4, 2025

    @coreh

    I'm also hitting this on 6.18.0 with @prisma/adapter-pg

  7. wmadden-electric commented on Nov 20, 2026

    @wmadden-electric
    Contributor

    Fixed on v7 by #29067: with a schema option, PrismaPg now sets the connection's search_path to that schema (followed by public), so TypedSQL and raw queries with unqualified table names resolve in it.

  8. wmadden-electric commented on Nov 24, 2026

    @wmadden-electric
    Contributor

    Reopening. #29067 closed this by making the Postgres adapter set search_path on 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's schema option.

    Until there is a fix that is safe behind connection poolers, two things work today:

    • Name the schema in the raw SQL: SELECT * FROM "mySchema"."User".
    • Set the search path on the database role: ALTER ROLE app_user SET search_path = "mySchema", public;
  9. added a commit that references this issue on Nov 24, 2026
    e9d17e5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bugtopic: driverAdapterstopic: postgresqltopic: typedSql

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions