-
-
Notifications
You must be signed in to change notification settings - Fork 481
Error querying PgBouncer #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It looks like PGBouncer doesn't support prepared statements. You can use The non-prepared statement API doesn't behave like the prepared statement API, so you won't be able to use the |
How can I do that? |
This is the (private) method that batch_execute wraps: https://github.com/sfackler/rust-postgres/blob/master/postgres/src/lib.rs#L953 |
That sounds like the right thing, but as you mentioned, it's private. How do you feel about exposing something like this through the public API? |
I tried this out -- simply changed the I'm thinking about adding a method similar to quick_query that would also provide To summarize this chain of thought, I'm proposing something like:
|
I don't think any interface returning |
Ahh it appears you're right. I was confused since the example I was debugging specified text format instead of binary in the row description, but apparently simple queries are a special case where the result is always text (except for binary cursors). In any case, it might still be helpful to return a pub trait GenericConnection {
// ...
/// New method on GenericConnection; sends a simple "Query" frame
///
/// Returns `Vec<TextRows>` since there may be multiple, semicolon delimited
/// queries in the `query` string. From a protocol level, each query yields T, D, C
/// (row description, data row(s), command completion), and finally a "ready
/// for query" frame Z is returned.
fn simple_query(&self, query: &str) -> Result<Vec<TextRows>>;
}
/// Result of one query sent via the `simple_query` API.
struct TextRows {
/// Result of parsing Row description for query
columns: Vec<Column>,
/// Data rows returned in text format
rows: Vec<RowData>,
}
/// One Row whose data is only available in string format
struct TextRow {
columns: &[Column],
raw: &RowData,
}
// Mirror existing Rows/Row APIs where it makes sense
impl IntoIterator for &TextRows {}
impl TextRows {
fn columns(&self) -> &[Column];
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn get(&self, idx) -> TextRow;
fn iter(&self) -> TextRowIter;
}
impl TextRow {
fn columns(&self) -> &[Column];
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
fn get<I: RowIndex>(&self, idx: I) -> &str;
fn get_opt<I: RowIndex>(&self, idx: I) -> Option<&str>;
} |
Started implementing this and realized it would be easier to store |
That seems like a reasonable setup I think. |
Closing this since all relevant info is in #304. |
@sfackler I had to go this route to solve the pgbouncer prepared statement problem as well. Although, it seems like we should have a better solution. I was able to get it functional, but my personal complication came around having a column of I'm far from having a good understanding of the postgres programming interface, but I was trying to do something as simple as |
Postgres has 2 query protocols - "simple" and "extended": https://www.postgresql.org/docs/12/protocol-flow.html#id-1.10.5.7.4. pgbouncer only handles the simple protocol properly due to how it routes requests, but that protocol doesn't support important features like query parameters. |
I understand that, but in my case I'm just trying to query with a string literal and I'm not using prepared statements at all.
Something this simple now requires me to use the Again, I'm no expert on the protocol itself, but I can use pgbouncer and jdbc totally transparently with parameterized queries that are more complex than my example above. |
I have also encountered this issue, and have revised my code to use
I'm a bit confused about how this interacts with the advice in this issue to use If so, what is the correct way to use pgbouncer for all Postgres queries (which, of course, includes queries with user-provided parameters)? Thanks very much for any help and for rust-postgres as a whole! |
I'm baffled with this situation in Rust. |
@codesections The |
PgBouncer seems to implement some, but not all, of the postgres protocol. Specifically, I was running into this error when trying to query it:
The error message is from PgBouncer internals (admin.c:1365). Basically, looks like the
'P'
frame isn't handled. This is generated frompostgres_protocol::messages::frontend::parse
.Any suggestions on how to resolve?
The text was updated successfully, but these errors were encountered: