sql

valerauko 2024-10-24T07:37:18.324889Z

Using next.jdbc with hikaricp and postgres, what would be the "correct" way to use prepared statements across threads?

igrishaev 2024-10-24T07:45:56.838779Z

In general, don't rely on prepared statements (at least in Postgres) a lot because of two things. 1. In postgres, prepared statements are bound to a certain connection. If you made a prepared statement X in a connection A, you can call X only via A. Calling it from connection B will end up with an error. Since you're working with a connection pool, there is no guarantee you have the same connection all the time. 2. JDBC driver for Postgres caches prepared statements under the hood. Every time you execute something, the prepared connection is cached by the hash from the SQL query. When you execute the same query with different parameters, the driver checks if there is a prepared statement for this hash, and uses it.

Martynas Maciulevičius 2024-12-18T21:32:45.078989Z

Why is the second thing bad? So it doesn't rerun the query?