16.5. PL/Python Extension for Autonomous Transactions

In addition to the subtransaction method, PL/Python module provides the autonomous method that can be used in the WITH clause to start an autonomous transaction:

CREATE OR REPLACE FUNCTION pythonomous() RETURNS void AS $$
        plpy.execute("INSERT INTO atx_test VALUES ('asd', 123)")

        try:
                with plpy.autonomous():
                        plpy.execute("INSERT INTO atx_test VALUES ('bsd', 456)")
        except plpy.SPIError, e:
                print("error: %s" % e.args)

        plpy.execute("INSERT INTO atx_test VALUES ('csd', 'csd')")
$$ LANGUAGE plpythonu;

Note

You cannot redefine isolation level for autonomous transactions within PL/Python blocks.

Exception handling for autonomous transactions in PL/Python is done in the same way as for subtransactions.

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy