public inbox for [email protected]  
help / color / mirror / Atom feed
From: Flaris Feller <[email protected]>
To: [email protected]
Subject: Transaction control in a C language function
Date: Mon, 6 Mar 2023 07:36:32 -0300
Message-ID: <CANNsrHt-3wC-nGG_owzfKfx+N-sHWFuJQ=QEivGrXGK2_ne0xA@mail.gmail.com> (raw)

Hello all,

I would like to implement transaction control in a function implemented in
C language. Currently I'm using SPI to do the job.
When calling SPI_commit() it returns this error message:
SQL Error [XX000]: ERROR: portal snapshots (0) did not account for all
active snapshots (1)
Below, there is an example.

PG_FUNCTION_INFO_V1(my_commit);

Datum my_commit(PG_FUNCTION_ARGS)
{
    SPIExecuteOptions execopts;

    SPI_connect_ext(SPI_OPT_NONATOMIC);

    memset(&execopts, 0, sizeof(execopts));
    execopts.params = NULL;
    execopts.read_only = false;
    execopts.allow_nonatomic = true;
    execopts.must_return_tuples = false;
    execopts.tcount = 0;
    execopts.dest = NULL;
    execopts.owner = NULL;

    /* Execute some SQL commands */
    SPI_execute_extended("UPDATE mytable SET name = 'done'", &execopts);

    /* Commit the transaction */
    SPI_commit();

    SPI_finish();

    PG_RETURN_NULL();
}

Thanks in advance,
Flaris Feller


view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Transaction control in a C language function
  In-Reply-To: <CANNsrHt-3wC-nGG_owzfKfx+N-sHWFuJQ=QEivGrXGK2_ne0xA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox