From 540a5466b8ec4f4e050d20e9bac23e9aa6d789ef Mon Sep 17 00:00:00 2001 From: Kould <2435992353@qq.com> Date: Mon, 25 Mar 2024 22:22:43 +0800 Subject: [PATCH] fix: encode_tuples add `LogicalType::Time` --- src/bin/server.rs | 1 + src/types/value.rs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/src/bin/server.rs b/src/bin/server.rs index f57b5dab..70747931 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -203,6 +203,7 @@ fn encode_tuples<'a>(schema: &Schema, tuples: Vec) -> PgWireResult encoder.encode_field(&value.date()), LogicalType::DateTime => encoder.encode_field(&value.datetime()), + LogicalType::Time => encoder.encode_field(&value.time()), LogicalType::Decimal(_, _) => todo!(), _ => unreachable!(), }?; diff --git a/src/types/value.rs b/src/types/value.rs index 96f4b818..ff0b1a07 100644 --- a/src/types/value.rs +++ b/src/types/value.rs @@ -282,6 +282,14 @@ impl DataValue { } } + pub fn time(&self) -> Option { + if let DataValue::Time(Some(val)) = self { + NaiveTime::from_num_seconds_from_midnight_opt(*val, 0) + } else { + None + } + } + pub(crate) fn check_len(&self, logic_type: &LogicalType) -> Result<(), DatabaseError> { let is_over_len = match (logic_type, self) { (LogicalType::Varchar(Some(len)), DataValue::Utf8(Some(val))) => {