Skip to content

Commit 8449e4d

Browse files
authored
Merge pull request sfackler#1027 from sfackler/oidvector
Fix serialization of oidvector
2 parents 8b9b5d0 + e71335e commit 8449e4d

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

postgres-types/src/lib.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,15 @@ impl<'a, T: ToSql> ToSql for &'a [T] {
910910
_ => panic!("expected array type"),
911911
};
912912

913+
// Arrays are normally one indexed by default but oidvector *requires* zero indexing
914+
let lower_bound = match *ty {
915+
Type::OID_VECTOR => 0,
916+
_ => 1,
917+
};
918+
913919
let dimension = ArrayDimension {
914920
len: downcast(self.len())?,
915-
lower_bound: 1,
921+
lower_bound,
916922
};
917923

918924
types::array_to_sql(

tokio-postgres/src/connect_socket.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ pub(crate) async fn connect_socket(
1414
host: &Host,
1515
port: u16,
1616
connect_timeout: Option<Duration>,
17-
tcp_user_timeout: Option<Duration>,
17+
#[cfg_attr(not(target_os = "linux"), allow(unused_variables))] tcp_user_timeout: Option<
18+
Duration,
19+
>,
1820
keepalive_config: Option<&KeepaliveConfig>,
1921
) -> Result<Socket, Error> {
2022
match host {

tokio-postgres/tests/test/types/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -739,3 +739,14 @@ async fn ltxtquery_any() {
739739
)
740740
.await;
741741
}
742+
743+
#[tokio::test]
744+
async fn oidvector() {
745+
test_type(
746+
"oidvector",
747+
// NB: postgres does not support empty oidarrays! All empty arrays are normalized to zero dimensions, but the
748+
// oidvectorrecv function requires exactly one dimension.
749+
&[(Some(vec![0u32, 1, 2]), "ARRAY[0,1,2]"), (None, "NULL")],
750+
)
751+
.await;
752+
}

0 commit comments

Comments
 (0)