Postgres driver ignores `.persistent(false)`
Bug Description
It is not presently possible to turn off the Postgres driver's use of named prepared statements. This is a blocker for users whose database doesn't support these. For example, Supabase has introduced a new pooler for all hosted instances which doesn't presently support saving these statements, so sqlx no longer works with that service.
I discovered this sqlx limitation via Discord. In a thread there, @abonander said:
The real issue is that the Postgres driver always uses named prepared statements, even if you set
.persistent(false)It doesn't have to, that's just how it's currently written.
Minimal Reproduction
I don't know how to provide this given that my reproduction steps involve using the Supabase hosted service with credentials and whatnot. However, the issue is independent of that.
Info
- SQLx version: 0.7.3
- SQLx features enabled: ["runtime-tokio-rustls", "json"]
- Database server and version: Postgres 15.1 (Supabase hosted)
- Operating system: macOS Sonoma 14.1.2
rustc --version: rustc 1.77.1 (7cf61ebde 2024-03-27)
It's not that it ignores the flag, strictly speaking. It does as it says on the tin: it won't retain the prepared statement after execution.
The problem is that it always prepares the statement with an explicit name because it uses the same code path for both cases.
Is this something that a newish Rust programmer would have a chance implementing? Is it just about using a random statement name each time when the persistent flag is set to false? If it's not too complex a solution, I'd appreciate a pointer to where to make the change.
Is this where the code is? Any pointers on what needs to change? I'm assuming it has something to do with get_or_prepare_statement…
If I can fork sqlx and make a change, just so I can get my little project working, that would be fantastic.
@nk9 I think you meant to reference here because that's where the postgres driver does a similar action as to what you linked in the MySQL driver