© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Drizzle TeamDT
Drizzle Team•3y ago•
8 replies
DammitMoonMoon

"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');
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();
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 - A New Way to Chat with Friends & Communities
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 - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Drizzle TeamJoin
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
11,879Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Prepared Statement - Neon Syntax Error
Drizzle TeamDTDrizzle Team / help
3y ago
Transaction + prepared statement
Drizzle TeamDTDrizzle Team / help
3y ago
Prepared statement returns undefined
Drizzle TeamDTDrizzle Team / help
3y ago
Neon DB pooled connection prepared statement error
Drizzle TeamDTDrizzle Team / help
3y ago