Skip to content

Commit 23d2524

Browse files
authored
Merge pull request sfackler#1028 from sfackler/int2vector
Fix int2vector serialization
2 parents 8449e4d + d92b3b0 commit 23d2524

File tree

2 files changed

+13
-2
lines changed
  • postgres-types/src
  • tokio-postgres/tests/test/types

2 files changed

+13
-2
lines changed

postgres-types/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -910,9 +910,9 @@ 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
913+
// Arrays are normally one indexed by default but oidvector and int2vector *require* zero indexing
914914
let lower_bound = match *ty {
915-
Type::OID_VECTOR => 0,
915+
Type::OID_VECTOR | Type::INT2_VECTOR => 0,
916916
_ => 1,
917917
};
918918

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

+11
Original file line numberDiff line numberDiff line change
@@ -750,3 +750,14 @@ async fn oidvector() {
750750
)
751751
.await;
752752
}
753+
754+
#[tokio::test]
755+
async fn int2vector() {
756+
test_type(
757+
"int2vector",
758+
// NB: postgres does not support empty int2vectors! All empty arrays are normalized to zero dimensions, but the
759+
// oidvectorrecv function requires exactly one dimension.
760+
&[(Some(vec![0i16, 1, 2]), "ARRAY[0,1,2]"), (None, "NULL")],
761+
)
762+
.await;
763+
}

0 commit comments

Comments
 (0)