You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This enables usage with pgBouncer's transaction mode. Typically when
using the transaction mode, a client gets a new connection from
pgBouncer for every new transaction. It's quite useful and allows one to
use prepared statements in this mode. The workflow goes:
```sql
-- start a new transaction
BEGIN
-- deallocate all stored statements from the server to prevent
-- collisions
DEALLOCATE ALL
-- run the queries here
-- ..
-- ..
COMMIT -- or ROLLBACK
```
Now in a case where the query uses custom types such as enums, what
tokio-postgres does is it fetches the type info for the given type,
stores the info to the cache and also caches the statements for
fetching the info to the client. Now when we have two tables with
different custom types in both of them, we can imagine the following
workflow:
```rust
// first query
client.simple_query("BEGIN")?;
client.simple_query("DEALLOCATE ALL")?;
let stmt = client.prepare("SELECT \"public\".\"User\".\"id\", \"public\".\"User\".\"userType\" FROM \"public\".\"User\" WHERE 1=1 OFFSET $1")?;
dbg!(client.query(&stmt, &[&0i64])?);
client.simple_query("COMMIT")?;
// second query
client.simple_query("BEGIN")?;
client.simple_query("DEALLOCATE ALL")?;
let stmt = client.prepare("SELECT \"public\".\"Work\".\"id\", \"public\".\"Work\".\"workType\" FROM \"public\".\"Work\" WHERE 1=1 OFFSET $1")?;
dbg!(client.query(&stmt, &[&0i64])?);
client.simple_query("COMMIT")?;
```
The `userType` and `workType` are both enums, and the preparing of the
second query will give an error `prepared statement "s1" does not
exist`, where `s1` is the query to the `pg_catalog` for the type info.
The change here gives an extra flag for the client to disable caching
of statements.
0 commit comments