Movatterモバイル変換


[0]ホーム

URL:



Facebook
Postgres Pro
Facebook
Downloads
45.8. Transaction Management
Prev UpChapter 45. PL/Python — Python Procedural LanguageHome Next

45.8. Transaction Management#

In a procedure called from the top level or an anonymous code block (DO command) called from the top level it is possible to control transactions. To commit the current transaction, callplpy.commit(). To roll back the current transaction, callplpy.rollback(). (Note that it is not possible to run the SQL commandsCOMMIT orROLLBACK viaplpy.execute or similar. It has to be done using these functions.) After a transaction is ended, a new transaction is automatically started, so there is no separate function for that.

Here is an example:

CREATE PROCEDURE transaction_test1()LANGUAGE plpython3uAS $$for i in range(0, 10):    plpy.execute("INSERT INTO test1 (a) VALUES (%d)" % i)    if i % 2 == 0:        plpy.commit()    else:        plpy.rollback()$$;CALL transaction_test1();

Transactions cannot be ended when an explicit subtransaction is active.


Prev Up Next
45.7. Explicit Subtransactions Home 45.9. Utility Functions
pdfepub
Go to Postgres Pro Standard 16
By continuing to browse this website, you agree to the use of cookies. Go toPrivacy Policy.

[8]ページ先頭

©2009-2025 Movatter.jp