diff --git a/nexus/peer-postgres/src/stream.rs b/nexus/peer-postgres/src/stream.rs index 230d2dca7d..6d2f6a6e1d 100644 --- a/nexus/peer-postgres/src/stream.rs +++ b/nexus/peer-postgres/src/stream.rs @@ -186,6 +186,12 @@ fn values_from_row(row: &Row) -> Vec { let uuid: Option = row.get(i); uuid.map(Value::Uuid).unwrap_or(Value::Null) } + &Type::UUID_ARRAY => { + let uuid: Option> = row.get(i); + uuid.map(ArrayValue::Uuid) + .map(Value::Array) + .unwrap_or(Value::Null) + } &Type::INET | &Type::CIDR => { let s: Option = row.get(i); s.map(Value::IpAddr).unwrap_or(Value::Null) diff --git a/nexus/value/src/array.rs b/nexus/value/src/array.rs index 2fa299bb34..9117dbf568 100644 --- a/nexus/value/src/array.rs +++ b/nexus/value/src/array.rs @@ -4,6 +4,7 @@ use bytes::{BufMut, Bytes, BytesMut}; use chrono::{DateTime, NaiveDate, NaiveTime, Utc}; use pgwire::types::ToSqlText; use postgres_types::{IsNull, ToSql, Type}; +use uuid::{Uuid, fmt::Hyphenated}; #[derive(Debug, PartialEq, Clone)] pub enum ArrayValue { @@ -21,6 +22,7 @@ pub enum ArrayValue { Text(Vec), Binary(Vec), VarBinary(Vec), + Uuid(Vec), Date(Vec), Time(Vec), TimeWithTimeZone(Vec), @@ -94,6 +96,11 @@ impl ArrayValue { .map(|v| serde_json::Value::String(hex::encode(v))) .collect(), ), + ArrayValue::Uuid(arr) => serde_json::Value::Array( + arr.iter() + .map(|v| serde_json::Value::String(v.to_string())) + .collect(), + ), ArrayValue::Date(arr) => serde_json::Value::Array( arr.iter() .map(|&v| serde_json::Value::String(v.to_string())) @@ -151,6 +158,7 @@ impl ToSql for ArrayValue { ArrayValue::Text(arr) => arr.to_sql(ty, out)?, ArrayValue::Binary(_arr) => todo!("support encoding array of binary"), ArrayValue::VarBinary(_arr) => todo!("support encoding array of varbinary"), + ArrayValue::Uuid(arr) => arr.to_sql(ty, out)?, ArrayValue::Date(arr) => arr.to_sql(ty, out)?, ArrayValue::Time(arr) => arr.to_sql(ty, out)?, ArrayValue::TimeWithTimeZone(arr) => arr.to_sql(ty, out)?, @@ -229,6 +237,14 @@ impl ToSqlText for ArrayValue { ArrayValue::Text(arr) => array_to_sql_text!(arr, ty, out), ArrayValue::Binary(_arr) => todo!("implement encoding array of binary"), ArrayValue::VarBinary(_arr) => todo!("implement encoding array of varbinary"), + ArrayValue::Uuid(arr) => { + let mut buf = [0u8; Hyphenated::LENGTH]; + for v in arr { + out.put_slice(b"'"); + out.put_slice(v.hyphenated().encode_lower(&mut buf).as_bytes()); + out.put_slice(b"',"); + } + } ArrayValue::Date(arr) => array_to_sql_text!(arr, ty, out), ArrayValue::Time(arr) => array_to_sql_text!(arr, ty, out), ArrayValue::TimeWithTimeZone(arr) => array_to_sql_text!(arr, ty, out),