Skip to content

Fix serialization of oidvector #1027

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

Merged
merged 1 commit into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion postgres-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion tokio-postgres/src/connect_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions tokio-postgres/tests/test/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}