I wrote the following to fetch the next value in a sequence. It works perfectly:
static int64 _get_md_key_next_serial()
{
int ret = SPI_execute("SELECT nextval('md_key_seq')", true, 1);
if (ret <= 0)
return (int64)ret;
if (SPI_processed)
{
SPITupleTable *tuptable = SPI_tuptable;
bool fieldNull;
Datum datum = SPI_getbinval(tuptable->vals[0], tuptable->tupdesc, 1, &fieldNull);
if (!fieldNull)
return DatumGetInt64(datum);
}
return NULL_ZERO;
}
However, surely there is a function call I can make without having to go through SPI?