Do prepared statement names matter?

Should we make sure that the names of prepared statements are unique in any way? If so, unique globally or within a block scope? For example, is this a problem within the same block?
const prepared = db.select().from(customers).prepare("statement_name");

const prepared2 = db.select().from(customers).prepare("statement_name");
const prepared = db.select().from(customers).prepare("statement_name");

const prepared2 = db.select().from(customers).prepare("statement_name");
5 Replies
SKUZZIE
SKUZZIEOP3w ago
I guess the Postgres docs clarifies a bit:
An arbitrary name given to this particular prepared statement. It must be unique within a single session and is subsequently used to execute or deallocate a previously prepared statement.
But the wording on the Drizzle docs makes it sound like the statement is prepared within Drizzle, not the database:
With prepared statements you do SQL concatenation once on the Drizzle ORM side and then database driver is able to reuse precompiled binary SQL instead of parsing query all the time.
Angelelz
Angelelz3w ago
This is a really good question, please take my answer with a grain of salt. I've worked in the drizzle codebase and I've always wondered about this... Drizzle prepared statements are separate from the database prepared statement, to the best of my knowledge
SKUZZIE
SKUZZIEOP3w ago
Interesting. If Drizzle prepared statements are separate I don't see the need for the name other than for identifying it in logging. I'm curious if someone who knows more about it can chime in.
Angelelz
Angelelz3w ago
@Dan Do you mind give us a quick insight into this?
Dan
Dan3w ago
no, if the statement name is required, it's only because it's required in the underlying driver, so I would say they are used on the DB level
Want results from more Discord servers?
Add your server