public inbox for [email protected]
help / color / mirror / Atom feedTransaction control in a C language function
3+ messages / 2 participants
[nested] [flat]
* Transaction control in a C language function
@ 2023-03-06 10:36 Flaris Feller <[email protected]>
2023-03-06 15:21 ` Re: Transaction control in a C language function Tom Lane <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Flaris Feller @ 2023-03-06 10:36 UTC (permalink / raw)
To: [email protected]
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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Transaction control in a C language function
2023-03-06 10:36 Transaction control in a C language function Flaris Feller <[email protected]>
@ 2023-03-06 15:21 ` Tom Lane <[email protected]>
2023-03-06 23:33 ` Re: Transaction control in a C language function Flaris Feller <[email protected]>
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2023-03-06 15:21 UTC (permalink / raw)
To: Flaris Feller <[email protected]>; +Cc: [email protected]
Flaris Feller <[email protected]> writes:
> I would like to implement transaction control in a function implemented in
> C language.
That will certainly not work unless you make it a procedure.
It'd be a good idea also to check that the CALL came from a
non-atomic context.
regards, tom lane
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Transaction control in a C language function
2023-03-06 10:36 Transaction control in a C language function Flaris Feller <[email protected]>
2023-03-06 15:21 ` Re: Transaction control in a C language function Tom Lane <[email protected]>
@ 2023-03-06 23:33 ` Flaris Feller <[email protected]>
0 siblings, 0 replies; 3+ messages in thread
From: Flaris Feller @ 2023-03-06 23:33 UTC (permalink / raw)
To: Tom Lane <[email protected]>; +Cc: [email protected]
Hello Tom,
You are absolutely right, I was calling it from a function instead of a
procedure.
The documentation should mention that.
Thanks for your clarification.
Regards,
Flaris.
Em seg., 6 de mar. de 2023 às 12:21, Tom Lane <[email protected]> escreveu:
> Flaris Feller <[email protected]> writes:
> > I would like to implement transaction control in a function implemented
> in
> > C language.
>
> That will certainly not work unless you make it a procedure.
> It'd be a good idea also to check that the CALL came from a
> non-atomic context.
>
> regards, tom lane
>
--
Flaris Roland Feller
https://www.linkedin.com/in/flarisfeller
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2023-03-06 23:33 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 10:36 Transaction control in a C language function Flaris Feller <[email protected]>
2023-03-06 15:21 ` Tom Lane <[email protected]>
2023-03-06 23:33 ` Flaris Feller <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox