Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow to rollback a transaction gracefully #500

Open
Newbie012 opened this issue Oct 8, 2022 · 3 comments
Open

allow to rollback a transaction gracefully #500

Newbie012 opened this issue Oct 8, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@Newbie012
Copy link
Contributor

Currently, there's no way to roll back a transaction without throwing an exception inside of it.

I was hoping for something like sql.rollback()

@porsager
Copy link
Owner

That's a great idea!

@apjoseph
Copy link

@Newbie012 To achieve this effect with current functionality, you can just execute

tx`ROLLBACK;`

inside the transaction.

You'll see this warning when the transaction attempts to commit:

{
  severity_local: 'WARNING',
  severity: 'WARNING',
  code: '25P01',
  message: 'there is no transaction in progress',
  file: 'xact.c',
  line: '3898',
  routine: 'EndTransactionBlock'
}

but it's harmless.

To avoid this message, if you are using Postgres 12 , you can simply run:

tx`ROLLBACK AND CHAIN;`

Which will immediately start a new transaction after the other is rolled back.

@Newbie012
Copy link
Contributor Author

Thanks @apjoseph

I'm not in a hurry, so I guess I'll wait for official implementation. Thanks again for the workaround! 🙂

@porsager porsager added the enhancement New feature or request label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants