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
When using prepared statements with Postgres, it's sometimes necessary to provide type hints in order to let the server know the type of statement parameters, particularly when it can not otherwise be inferred. In terms of the tokio-postgres API this corresponds to using prepare_typed instead of prepare.
For example, the following query prepared via sea_query will fail when using prepare:
My interpretation of this error is that the server is inferring the $1 slot as a string, and when the binary encoded integer is sent, the server rejects it as invalidly encoded (Postgres has incorrect but consistent behavior when handling null bytes in UTF8 strings).
This is a simplified example so it may not be obvious why this is important, but it's not too difficult to find real world examples where the server is unable to infer a parameter type correctly. The usual solution is to use prepare_typed(), but I do not believe it's currently possible to get the necessary &[postgres_types::Type] from the sea_query query.
Proposed Solutions
Add an API to retrieve the list of parameter types of a sea_query query. I suggest the function signature: sea_query_postgres::PostgresValues::as_types(&self) -> Vec<postgres_types::Type>.
The text was updated successfully, but these errors were encountered:
Motivation
When using prepared statements with Postgres, it's sometimes necessary to provide type hints in order to let the server know the type of statement parameters, particularly when it can not otherwise be inferred. In terms of the
tokio-postgres
API this corresponds to usingprepare_typed
instead ofprepare
.For example, the following query prepared via
sea_query
will fail when usingprepare
:fails with the following
Debug
formatted error:My interpretation of this error is that the server is inferring the
$1
slot as a string, and when the binary encoded integer is sent, the server rejects it as invalidly encoded (Postgres has incorrect but consistent behavior when handling null bytes in UTF8 strings).This is a simplified example so it may not be obvious why this is important, but it's not too difficult to find real world examples where the server is unable to infer a parameter type correctly. The usual solution is to use
prepare_typed()
, but I do not believe it's currently possible to get the necessary&[postgres_types::Type]
from thesea_query
query.Proposed Solutions
Add an API to retrieve the list of parameter types of a
sea_query
query. I suggest the function signature:sea_query_postgres::PostgresValues::as_types(&self) -> Vec<postgres_types::Type>
.The text was updated successfully, but these errors were encountered: