pgrx
pgrx copied to clipboard
how to read data using SPI ?
hello, everyone, i reaally need some help here I got a table where each column in integer. I want to select some data using the server programming interface provided by pgrx.spi.
This code helps,
let _ = Spi::connect(|client| {
let query = format!("SELECT * FROM {} {} LIMIT {}", dataset, SQL, batch_size);
let mut cursor = client.open_cursor(&query, None);
let table = match cursor.fetch(batch_size as c_long) {
Ok(table) => table,
Err(e) => return Err(e.to_string()),
};
for row in the table.into_iter() {
for i in 3..=row.columns() {
if let Ok(Some(val)) = row.get::<i32>(i) {
all_rows.push(val);
}
}
}
However, now one problem here: I need to further execute a for loop to iterate all columns and all rows, this is too slow>
Is there any method that can skip such for loop? and directly get the result as a Vec
let mut all_rows = Vec::new();