Skip to content

Commit 38ddd42

Browse files
diegoimbertMaxxen
authored andcommitted
Statement::column_logical_type
1 parent 0159fe3 commit 38ddd42

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

crates/duckdb/src/column.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::str;
22

33
use arrow::datatypes::DataType;
44

5-
use crate::{Error, Result, Statement};
5+
use crate::{core::LogicalTypeHandle, Error, Result, Statement};
66

77
/// Information about a column of a DuckDB query.
88
#[derive(Debug)]
@@ -160,6 +160,14 @@ impl Statement<'_> {
160160
pub fn column_type(&self, idx: usize) -> DataType {
161161
self.stmt.column_type(idx)
162162
}
163+
164+
/// Returns the declared logical data type of the column.
165+
///
166+
/// # Caveats
167+
/// Panics if the query has not been [`execute`](Statement::execute)d yet.
168+
pub fn column_logical_type(&self, idx: usize) -> LogicalTypeHandle {
169+
self.stmt.column_logical_type(idx)
170+
}
163171
}
164172

165173
#[cfg(test)]

crates/duckdb/src/raw_statement.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use arrow::{
99
use super::{ffi, Result};
1010
#[cfg(feature = "polars")]
1111
use crate::arrow2;
12-
use crate::{error::result_from_duckdb_arrow, Error};
12+
use crate::{core::LogicalTypeHandle, error::result_from_duckdb_arrow, Error};
1313

1414
/// Private newtype for DuckDB prepared statements that finalize themselves when dropped.
1515
///
@@ -215,6 +215,12 @@ impl RawStatement {
215215
self.schema().field(idx).data_type().to_owned()
216216
}
217217

218+
#[inline]
219+
pub fn column_logical_type(&self, idx: usize) -> LogicalTypeHandle {
220+
let ptr = unsafe { ffi::duckdb_column_logical_type(&mut self.duckdb_result.unwrap() as *mut _, idx as u64) };
221+
LogicalTypeHandle { ptr }
222+
}
223+
218224
#[inline]
219225
pub fn schema(&self) -> SchemaRef {
220226
self.schema.clone().unwrap()

0 commit comments

Comments
 (0)