"Prepared statement already exists" error

I'm experiencing a problem with Drizzle ORM and Vercel’s Postgres (which I believe is Neon Postgres under the hood) in my SvelteKit application deployed on Vercel. Everything functioned perfectly until I tried to transition my request handling to edge functions using prepared statements.

Here’s what I've implemented:
  1. Defined a prepared statement in a separate file:```export const getPublishedJokesPrep = db.select().from(jokesTable).where(eq(jokesTable.isPublished, true)).orderBy(desc(jokesTable.votes)).prepare('getPublishedJokesPrep');```
  2. Executed the prepared statement in the request handler:`getPublishedJokesPrep.execute();`
The first execution works fine, but subsequent ones trigger a “prepared statement already exists” error. It seems each request to the handler tries to recreate the prepared statement.

This issue seems similar to what others have encountered (helpWhat exactly i am doing wrong.. Prepared Query, help.prepare() in Next.js App Router), but there are no solutions in these threads.

Has anyone faced and resolved this? Any insights into the root cause or potential solutions would be greatly appreciated.
Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Was this page helpful?