Replies: 5 comments
-
@chanan You are asking about raw sql query execution. There are instances where we need to write a complex query and ORMs don't have support then you can use this.
|
Beta Was this translation helpful? Give feedback.
-
Yes, but I am asking is we can call prepare on it? Sorry, I realize the text of my question wasn't clear. I am hoping to be able to do something along the lines of:
|
Beta Was this translation helpful? Give feedback.
-
@chanan There should be no need to use
Reference: Query Perf |
Beta Was this translation helpful? Give feedback.
-
Re-reading the documentation you shared, I see that maybe prepared statements aren't doing the same thing I am used to from SQL Server and .net. I assumed that it prepared statements would also re-use the query plan. In those cases where it re-uses a query plan, the performance of the dynamic SQL (that is prepared) is similar to a stored proc. From the above, I assume that is not the case here? |
Beta Was this translation helpful? Give feedback.
-
Postgres has prepared statements https://www.postgresql.org/docs/current/sql-prepare.html so I don't get why "it's not applicable to raw queries". It has to be. The other thing is that Drizzle + cross-database, works even for DBs without native It's unfortunate that two different, just somewhat related, concepts have a name clash. Update: documentation talks about "binary" compilation, making it look like let pgsql = ...PostgresJS client...
let dz = ...drizzle client...
// When executed via PostgresJS directly
await pgsql`SELECT 2 * 3000`
for (let r of await pgsql`SELECT * FROM pg_prepared_statements`) {
console.log(r) // ... `SELECT 2 * 3000` is cached
} // When executed via Drizzle
await dz.execute(sql`SELECT 2 * 4000 AS bar`)
for (let r of await dz.execute(sql`SELECT * FROM pg_prepared_statements`)) {
console.log(r) // ... `SELECT 2 * 4000` is NOT cached
} |
Beta Was this translation helpful? Give feedback.
-
Using MySQL is it possible to prepare a statement that is is an ad hoc statement such as:
Beta Was this translation helpful? Give feedback.
All reactions