pgrx
pgrx copied to clipboard
SpiClient.select(..).get_one() results in "SpiTupleTable positioned before start" error
The following code results in a runtime exception.
Spi::execute(|client| {
client
.select("Select 1", None, None)
.get_one::<i64>()
.unwrap();
});
It only works, if we call first() before get_one().
Spi::execute(|client| {
client
.select("Select 1", None, None)
.first()
.get_one::<i64>()
.unwrap();
});
Is there a particular reason, why spi.rs on line 369 initializes this field to -1 instead of 0? Can we maybe make first() deprecated and introduce a more expressive name like "reset_iterator" if it's required at all? Based on the name, I'd expect first() to return the first element of the iterator (even if next() is the idiomatic way to do so in rust). I'd be happy to make a pull request if I get instruction on what to do in this tracking issue.
I'd be happy with a PR that tidies this up a little bit. I'm fine with any more idiomatic thing you come up with. ;)