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?
5 Replies
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.
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
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.
@Dan Do you mind give us a quick insight into this?
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