From 846dcfe52af76d16efb2f3236a7f1cde0b05c6b3 Mon Sep 17 00:00:00 2001 From: Yudai Fukushima <49578068+granddaifuku@users.noreply.github.com> Date: Thu, 5 Oct 2023 08:56:14 +0900 Subject: [PATCH] fix: decode postgres time without subsecond (#2784) * fix: decode postgres time without subsecond * update: decode postgres time without subsecond by making subsecond optional --- sqlx-postgres/src/types/time/time.rs | 3 ++- tests/postgres/types.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sqlx-postgres/src/types/time/time.rs b/sqlx-postgres/src/types/time/time.rs index fcd40145..7a9b99d9 100644 --- a/sqlx-postgres/src/types/time/time.rs +++ b/sqlx-postgres/src/types/time/time.rs @@ -42,7 +42,8 @@ impl<'r> Decode<'r, Postgres> for Time { PgValueFormat::Text => Time::parse( value.as_str()?, - &format_description!("[hour]:[minute]:[second].[subsecond]"), + // Postgres will not include the subsecond part if it's zero. + &format_description!("[hour]:[minute]:[second][optional [.[subsecond]]]"), )?, }) } diff --git a/tests/postgres/types.rs b/tests/postgres/types.rs index 2b2de07f..dbb40929 100644 --- a/tests/postgres/types.rs +++ b/tests/postgres/types.rs @@ -321,7 +321,8 @@ mod time_tests { test_type!(time_time