-1

I am creating a Postgres function where I want to insert data into multiple tables and if any of them get failed then I want to rollback the transaction. But while writing the code begin transaction; in my function it says below error: ERROR: syntax error at or near "transaction"

1
  • 1
    Post your code... Commented Aug 3, 2017 at 23:16

1 Answer 1

1

PL/PgSQL functions cannot begin or commit transactions.

You appear to want autonomous transactions, but they are not supported.

Perhaps you can do what you need with a PL/PgSQL BEGIN ... EXCEPTION ... block. You can abort the (sub)transaction with a RAISE command to raise an error, instead of ROLLBACK.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.