pgrx icon indicating copy to clipboard operation
pgrx copied to clipboard

SpiClient.select(..).get_one() results in "SpiTupleTable positioned before start" error

Open mineichen opened this issue 4 years ago • 1 comments

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.

mineichen avatar Oct 19 '21 22:10 mineichen

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. ;)

eeeebbbbrrrr avatar Oct 27 '21 18:10 eeeebbbbrrrr