Subject: Run a transaction block through SPI_execute

From: mahendrakar s <[email-masked]>
Date: Thu, 23 Nov 2023 18:33:32 +0530

When I try to run a transaction block (similar) to below through SPI_execute:
BEGIN; set transaction read write; ....; COMMIT

I get an error: SPI_ERROR_TRANSACTION.

I see that SPI interface does not support transaction manipulation commands.

Documentation:  https://www.postgresql.org/docs/current/spi-spi-execute.html

Can you please suggest me how to achieve run the above transaction
block using SPI_ interface?

Transaction management support only SPI_commit/SPI_rollback.
I'm more interested in setting `set transaction read write;` through
SPI interface.

Thanks,
Mahendrakar.

---

From: Tom Lane <[email-masked]>
Date: Thu, 23 Nov 2023 10:47:45 -0500

> I see that SPI interface does not support transaction manipulation commands.

Yup; you can't execute begin/commit that way.

> I'm more interested in setting `set transaction read write;` through

You could look at how plpgsql handles it.  I think though that as
long as you do BEGIN and COMMIT in the approved way, you can feed
the SET through SPI_execute or one of its siblings.

			regards, tom lane