Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZ8DV-0002eq-TZ for pgsql-interfaces@arkaria.postgresql.org; Mon, 06 Mar 2023 10:37:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pZ8DU-0002dc-JY for pgsql-interfaces@arkaria.postgresql.org; Mon, 06 Mar 2023 10:37:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pZ8DU-0002dT-AC for pgsql-interfaces@lists.postgresql.org; Mon, 06 Mar 2023 10:37:16 +0000 Received: from mail-vs1-xe36.google.com ([2607:f8b0:4864:20::e36]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1pZ8DN-00075f-N6 for pgsql-interfaces@lists.postgresql.org; Mon, 06 Mar 2023 10:37:15 +0000 Received: by mail-vs1-xe36.google.com with SMTP id d7so8673208vsj.2 for ; Mon, 06 Mar 2023 02:37:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678099028; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=E0BEPvPbDJFUjZHLIIrud+XdlBV3yNxz9L8LJtVG/7M=; b=JQ1O8cHIpi/zjqEtqGVUlAdJVflIYjXwDq9S2FUK9Bmi4E6ObGYpXtsOC1uyiZHQvJ zfN86+I6/DPZAIrYLpfEJ2EeIUdnzbCbY/XluedxTjRo+lI91H2EgntDjnB2d+vMkC9S XbZL2OTmK/Rt3C9GMB+n87ikD1PyjNnz7tRjukwhaThnjeqNKNUtj1Fr5Se+43Z+9ON2 DjE+xpBUEkG9PF2kPVsbCD7NHigj9PZC6bXb0XNtAzM9wOMzPdikoDeKtBka2VLgCQUL +wLUZ93y63C+Ogw0PQSDeoJZ/1c6ZMEv8SY94rKV1fQpXrFlsTVrV46taxaMWjnFQJGe rc2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678099028; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=E0BEPvPbDJFUjZHLIIrud+XdlBV3yNxz9L8LJtVG/7M=; b=KrKM5APzJ9oiJfkRREg+nP6bYzS/EyFto8YVW4BKwXCkWlxhSgi5/90WDiTtBmNUD/ L7tO7YOsAzGt8UGr7Q/XVce1joCJg7SRHtnmLDww0xjRi3VmqNywIVJO8TIBa1+baqqG Ro/XZIctxADQR8lCH4z+lF1uDi4FPPWgjY2DK683WfaLHQ8MYJPp0kq4PKhGAc6OztqB ZyXsmiVOysDaEO7pzt6zYOq5l2MFlvaYHweaX+DaSUWrRojUB4ypyB6n3RQ4Zu9Y+ePE LA5hINXcQElCOMxpzb/cylh6hTcqu8w3mR701YhT8sjClyDHjekhFPf4WJ8Tg76G7zJ8 04FQ== X-Gm-Message-State: AO0yUKXKq3YFlLxkd3BP0/w9p2hTw1cuRp2tzNmgH6QgqJBpNGNz0Ivi IZKS5JYIA3L2BMvnxzRoJTDLQhreEqRNM2HrujAlfqjFOwE= X-Google-Smtp-Source: AK7set9OuZgv448IVbncvSv1HV4doXCmEEe10Sq85ntF2iT1TSEFLV8T4umFrrpu6Ydv4N0Iprda6ABNX9Nt0Hp2FaI= X-Received: by 2002:a67:f546:0:b0:412:27f7:491b with SMTP id z6-20020a67f546000000b0041227f7491bmr6837917vsn.2.1678099028101; Mon, 06 Mar 2023 02:37:08 -0800 (PST) MIME-Version: 1.0 From: Flaris Feller Date: Mon, 6 Mar 2023 07:36:32 -0300 Message-ID: Subject: Transaction control in a C language function To: pgsql-interfaces@lists.postgresql.org Content-Type: multipart/alternative; boundary="00000000000077d42305f638e0da" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000077d42305f638e0da Content-Type: text/plain; charset="UTF-8" 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 --00000000000077d42305f638e0da Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello all,

I would like to i= mplement transaction control in a function implemented in C language. Curre= ntly I'm using SPI to do the job.
When calling SPI_commit() i= t returns this error message:
SQL Error [XX000]: ERROR: portal sn= apshots (0) did not account for all active snapshots (1)
Below, t= here is an example.

PG_FUNCTION_INFO_V1(my_commit);

Da= tum my_commit(PG_FUNCTION_ARGS)
{
=C2=A0 =C2=A0 SPIExecuteOptions exe= copts;

=C2=A0 =C2=A0 SPI_connect_ext(SPI_OPT_NONATOMIC);

=C2= =A0 =C2=A0 memset(&execopts, 0, sizeof(execopts));
=C2=A0 =C2=A0 exe= copts.params =3D NULL;
=C2=A0 =C2=A0 execopts.read_only =3D false;
= =C2=A0 =C2=A0 execopts.allow_nonatomic =3D true;
=C2=A0 =C2=A0 execopts.= must_return_tuples =3D false;
=C2=A0 =C2=A0 execopts.tcount =3D 0;
= =C2=A0 =C2=A0 execopts.dest =3D NULL;
=C2=A0 =C2=A0 execopts.owner =3D N= ULL;

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

=C2=A0 =C2=A0 /* Commit the transaction */
=C2= =A0 =C2=A0 SPI_commit();

=C2=A0 =C2=A0 SPI_finish();

=C2=A0 = =C2=A0 PG_RETURN_NULL();
}

Thanks in advanc= e,
Flaris Feller
--00000000000077d42305f638e0da--