fix serialization of oidvector

This commit is contained in:
Steven Fackler 2023-05-01 19:33:49 -04:00
parent 8b9b5d0388
commit e71335ee43
No known key found for this signature in database
GPG Key ID: 408917B7276A5226
3 changed files with 21 additions and 2 deletions

View File

@ -910,9 +910,15 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
_ => panic!("expected array type"),
};
// Arrays are normally one indexed by default but oidvector *requires* zero indexing
let lower_bound = match *ty {
Type::OID_VECTOR => 0,
_ => 1,
};
let dimension = ArrayDimension {
len: downcast(self.len())?,
lower_bound: 1,
lower_bound,
};
types::array_to_sql(

View File

@ -14,7 +14,9 @@ pub(crate) async fn connect_socket(
host: &Host,
port: u16,
connect_timeout: Option<Duration>,
tcp_user_timeout: Option<Duration>,
#[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option<
Duration,
>,
keepalive_config: Option<&KeepaliveConfig>,
) -> Result<Socket, Error> {
match host {

View File

@ -739,3 +739,14 @@ async fn ltxtquery_any() {
)
.await;
}
#[tokio::test]
async fn oidvector() {
test_type(
"oidvector",
// NB: postgres does not support empty oidarrays! All empty arrays are normalized to zero dimensions, but the
// oidvectorrecv function requires exactly one dimension.
&[(Some(vec![0u32, 1, 2]), "ARRAY[0,1,2]"), (None, "NULL")],
)
.await;
}