Skip to content

Commit 58ac220

Browse files
committed
feat: add support for more parameter types
1 parent d994f4b commit 58ac220

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

datafusion-postgres/src/datatypes.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::sync::Arc;
22

3+
use chrono::{DateTime, Datelike, FixedOffset};
34
use chrono::{NaiveDate, NaiveDateTime};
45
use datafusion::arrow::array::*;
56
use datafusion::arrow::datatypes::*;
@@ -496,6 +497,10 @@ where
496497
let value = portal.parameter::<bool>(i, &pg_type)?;
497498
deserialized_params.push(ScalarValue::Boolean(value));
498499
}
500+
Type::CHAR => {
501+
let value = portal.parameter::<i8>(i, &pg_type)?;
502+
deserialized_params.push(ScalarValue::Int8(value));
503+
}
499504
Type::INT2 => {
500505
let value = portal.parameter::<i16>(i, &pg_type)?;
501506
deserialized_params.push(ScalarValue::Int16(value));
@@ -512,6 +517,11 @@ where
512517
let value = portal.parameter::<String>(i, &pg_type)?;
513518
deserialized_params.push(ScalarValue::Utf8(value));
514519
}
520+
Type::BYTEA => {
521+
let value = portal.parameter::<Vec<u8>>(i, &pg_type)?;
522+
deserialized_params.push(ScalarValue::Binary(value));
523+
}
524+
515525
Type::FLOAT4 => {
516526
let value = portal.parameter::<f32>(i, &pg_type)?;
517527
deserialized_params.push(ScalarValue::Float32(value));
@@ -527,7 +537,20 @@ where
527537
None,
528538
));
529539
}
530-
// TODO: add more types like Timestamp, Datetime, Bytea
540+
Type::TIMESTAMPTZ => {
541+
let value = portal.parameter::<DateTime<FixedOffset>>(i, &pg_type)?;
542+
deserialized_params.push(ScalarValue::TimestampMicrosecond(
543+
value.map(|t| t.timestamp_micros()),
544+
value.map(|t| t.offset().to_string().into()),
545+
));
546+
}
547+
Type::DATE => {
548+
let value = portal.parameter::<NaiveDate>(i, &pg_type)?;
549+
deserialized_params.push(ScalarValue::Date32(
550+
value.map(|date| date.num_days_from_ce()),
551+
));
552+
}
553+
// TODO: add more types
531554
_ => {
532555
return Err(PgWireError::UserError(Box::new(ErrorInfo::new(
533556
"FATAL".to_string(),

0 commit comments

Comments
 (0)