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

Transactions #410

Open
ThiefMaster opened this issue Nov 11, 2015 · 10 comments · May be fixed by #1354
Open

Transactions #410

ThiefMaster opened this issue Nov 11, 2015 · 10 comments · May be fixed by #1354

Comments

@ThiefMaster
Copy link

It would be nice if pgcli had some fancy handling for transactions. Things I could imagine:

  • Always start a transaction on startup. COMMIT/ROLLBACK would automatically start a new one.
  • Start a transaction implicitly as soon as you run any SQL command that modifies data (might be a bit obscure though).

When always having a transaction an automated ROLLBACK+BEGIN in case of an SQL error would be useful - that's actually one of the things I miss most in psql. Sometimes I want to try things and having to rollback+begin after a typo etc it somewhat annoying.

An undo feature could also be useful. Basically it'd ROLLBACK+BEGIN and then execute all statements since the start of the transaction besides that last one / last n ones again.

@amjith
Copy link
Member

amjith commented Nov 12, 2015

Interesting request.

But I'm still unclear when pgcli would commit. For example: When a user launches pgcli we start a transaction, then they explore using select, change data using insert or update or drop, then explore some more using select. In this workflow where does the commit happen? Do we keep all these commands in a transaction until they quit pgcli or type in COMMIT/ROLLBACK themselves?

@darikg I was thinking your latest changes to add the extra field for denoting success/failure of a query can be used to achieve the undo feature.

@ThiefMaster
Copy link
Author

But I'm still unclear when pgcli would commit.

I would only commit explicitly, i.e. by issuing a COMMIT statement. Of course this would need to be displayed on startup when transactions are enabled (and there could be an optional prompt on exit if there are uncommitted changes).

@fernandomora
Copy link
Contributor

I think this would be very useful as a mode that can be enabled/disabled with its status shownin the bottom bar like smart completion and multiline mode. When autocommit mode is ON its behaviour would be the standard one when no transaction is explicly started and when it is OFF, a commit is explicitly needed.

Improving autocommit off mode with an automatic start of a new transaction (ROLLBACK+BEGIN) when an errors fail as @ThiefMaster purpose would be great.

@j-bennet
Copy link
Contributor

This sounds like a nice feature to have. I like the idea of autocommit mode being displayed in the bottom status bar. We could also add a little indicator (like a red * or !) to show that user has uncommited changes - in addition to a warning on exit.

@fedragon
Copy link

fedragon commented Apr 6, 2016

I would love to see this feature coming to pgcli, I'm currently dealing with begin; ... commit; on my own but that makes it really prone to error, especially when dealing with production databases...

@mkataja
Copy link

mkataja commented Jun 2, 2016

Do note that there are PostgreSQL operations that can't be run inside a transaction (VACUUM comes to mind). This feature should be off by default.

@ztane
Copy link

ztane commented Aug 18, 2017

This should be possible to enable. Or, more specifically, the optional behaviour should/must match that of psql when run with

\set AUTOCOMMIT off
\set ON_ERROR_ROLLBACK interactive

And it should be possible to configure this as the default operation somehow. The ON_ERROR_ROLLBACK interactive in psql creates implicit savepoints over each command, and rolls them back on exception so that in case of a simple typo in my session I do not have to start again from scratch.

@biggerfisch
Copy link

It would be really nice to at least have the equivalent of psql's \set ON_ERROR_ROLLBACK interactive in pgcli. That's the only feature I really miss from psql. http://blog.endpoint.com/2015/02/postgres-onerrorrollback-explained.html might be helpful to anyone interested.

@aseemk
Copy link

aseemk commented Jan 3, 2018

Huge +1 that ON_ERROR_ROLLBACK support would be huge. A typo after a bunch of transactional work can be quite frustrating. =) Thank you for all your great work!

@Skoffer
Copy link

Skoffer commented Apr 4, 2018

\set AUTOCOMMIT off
is essential for any proper database developer work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants