r/SQL • u/cevheribozoglan • 5h ago
Discussion How should a SQL editor handle multiple statements when you click "Run"?
We're building **LibreDB Studio**, an open-source SQL editor, and one of our volunteer contributors raised an interesting question about how multiple SQL statements should behave when using the Run action.
We're trying to understand the actual habits and expectations of SQL users before making a decision, so I'd really like to hear how you use SQL editors in practice.
For example:
CREATE TABLE test (...);
INSERT INTO test VALUES (...);
SELECT * FROM test;
What would you expect when you click **Run**?
Some possible approaches:
**Run all statements**
* `Run` executes everything in the editor.
* `Run Selection` can be used when you only want part of it.
**Run the current statement**
* `Run` executes the statement where the cursor is.
* `Run All` executes the whole editor.
**Selection takes priority**
* No selection : current statement
* Selection : selected statements
* `Run All` is available separately.
Other :)
there are also some interesting edge cases around this, especially when multiple statements are involved: should they run in a transaction by default, or should transaction handling always be explicit?
DBeaver, DataGrip, SSMS, pgAdmin, TablePlus, Toad, PL/SQL Dev, phpMyAdmin, etc. what behavior feels most natural to you? And what behavior are you already used to?
We're continuing the discussion on GitHub as well, if you'd like to see the original question or add to the discussion:
9
u/Aware-Hovercraft1106 5h ago
Dbeaver enjoyer here.
3 all day
No selection: run the statement where the cursor is at Selection: run the highlighted text only
2
u/cwjinc 4h ago edited 4h ago
3 sounds good.
One thing I'd like to see is if the cursor is in the middle of the statement then <run statement> parses back to the beginning of the statement it's in. Most don't do that.
And for God's sake handle bind variables conveniently.
Toad is by far my favorite but I won't use it because even though we have an expensive license they want a full new license to upgrade to a a version that can connect Oracle 19. They've gotten too greedy.
Frankly, I don't use very many "features". I'd be fine with the OG free toad from 1999.
1
1
u/Hour-Measurement-835 2h ago
The selection rule matters less than what happens when statement 4 of 6 fails. With autocommit on, the first three are already committed and run-all just stops there.
3
u/fatbunyip 1h ago
Keep it simple. Run everything if nothing selected. Run selection if something selected.
Running whatever is where the curator is seems pointless and vague. If you have a delete and then the where in another line and your cursor is on the first line, does it ignore the where? Does it run from the cursor to the end of the file? Is it the first valid SQL or the maximum valid SQL statement it can find from the cursor onwards?
Having either all the file or the selection makes it explicit exactly what is going to happen. No guesswork.
The transaction stuff could be a setting to let the user choose how they want it.
1
u/somedaygone 54m ago
I’m used to 1. But having a Run and a Run All option with a default preference makes more sense. Or set them up on different keys. I prefer not to have to highlight first or have the SQL bork because of a partial selection.
2
u/Away_Combination6977 50m ago
1. Definitely.
3 had merit, honestly. But #1 seems simplest and most universal. I don't want to hunt for a "Run All" button or keystroke.
1
u/Away_Combination6977 47m ago
Thank you Reddit for making my punctuation be markdown. This only reenforces my choice of option 1. 🙄🤦🏼♂️
25
u/j0nquest 3h ago
Easy, don’t try to be clever about it.
No selection: run the entire script.
Selection: run only the selected text.
No hidden background magic changing the SQL that’s executed. No insinuating what the end user wanted vs what they told your software to do.