Skip to content

Commit 45429b1

Browse files
committed
fix pg i8 decode
1 parent 245a3ae commit 45429b1

File tree

1 file changed

+6
-1
lines changed
  • sqlx-core/src/postgres/types

1 file changed

+6
-1
lines changed

sqlx-core/src/postgres/types/int.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ impl Encode<'_, Postgres> for i8 {
3131
impl Decode<'_, Postgres> for i8 {
3232
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
3333
// note: in the TEXT encoding, a value of "0" here is encoded as an empty string
34-
let bytes: [u8; 1] = value.as_bytes()?[..1].try_into().unwrap_or_default();
34+
let bytes = value.as_bytes()?;
35+
let bytes: [u8; 1] = bytes
36+
.get(..1)
37+
.unwrap_or(&[0])
38+
.try_into()
39+
.unwrap_or_default();
3540
Ok(i8::from_be_bytes(bytes))
3641
}
3742
}

0 commit comments

Comments
 (0)