21

In MySQL Workbench, one can use the keyboard shortcut Ctrl + ENTER to execute the statement at cursor (delineated with semi colons).

Is there a similar shortcut in pgAdmin?


For SQL queries that span on only one line, I use a voice command in Dragon NaturallySpeaking:

Sub Main
    SendKeys "{End}"
    Wait(0.3)
    SendKeys "+{Home}"
    Wait(0.3)
    SendKeys "{F5}"
End Sub

enter image description here

but I don't have any solution for SQL queries that span although more than one line.

3
  • 1
    One of the most common tasks I do at work is check for postal codes that are entered in the correct format but are wrong. I need to group all cities and postal codes together, with counts of each. From the results, I then start selecting each of the employees - and then manually verifying the postal code .. then issuing an update statement. Its a manual process that can't be automated - but having to highlight before execute makes it insanely burdensome. Maybe I will suggest an improvement for pgadmin.
    – DHW
    Commented Jul 6, 2016 at 22:11
  • @DHW I filed a feature request: redmine.postgresql.org/issues/1439 Commented Jul 6, 2016 at 22:37
  • 2
    2023 and this handy feature is still missing. Disappointing.
    – Rafs
    Commented May 2, 2023 at 15:01

3 Answers 3

0

After eight years, I can happily announce that from pgAdmin version 4 - 8.7 it is possible to fully use the Execute query functionality using a keyboard shortcut.

If you are used to the shortcut CTRL+ENTER (or any other), which is supposed to run the query on which the cursor is currently located (bordered by semicolons), you must first set the keyboard shortcut in the preferences: File - Preferences - Query tool - Keyboard shortcuts - Execute query.

From then on, your shortcut will work as expected.

Example

Just one note: In this case, only the semicolon is taken into account, not the lines, i.e. if one query ends in one line and another begins right after semicolon, it depends on the position of the cursor in the line, whether it is before the semicolon (just after it still falls into the first query) or already in the next query. I think it behaves correctly.

Feature request: Missing Execute query functionality

8

Since there seems to be no way to define such a keyboard shortcut, I filed a feature request: https://redmine.postgresql.org/issues/1439 , which got rejected:

​Issue #1439 has been updated by Dave Page.

Status changed from New to Rejected

We follow the pgAdmin 3 behaviour in this regard - when you execute a query (or explain etc), if any text is selected, only that text is executed. If nothing is selected, the entire query (or set of queries) are executed.

Since amazingly with pgAdmin one has to login to view issues / feature request, here is a screenshot:

enter image description here

8
  • Great! I was going through the pgadmin source to see if I could make the change and submit a proposed patch but I think its beyond my level at the moment.
    – DHW
    Commented Jul 7, 2016 at 4:03
  • @DHW Feature request got rejected :( Commented Jul 7, 2016 at 20:31
  • 2
    I saw that. First of all, the Control+Shift+E is in reference to the current pgadmin 4 which is in beta. Second of all, it doesn't execute the current statement, it has the same behaviour as before - just a lot slower in this version. Disappointing when things get a knee-jerk reaction without any thought.
    – DHW
    Commented Jul 8, 2016 at 12:26
  • 3
    The whole point in having a keyboard shortcut is to avoid needing to use the mouse, which is required in order to select the text of the query to execute. It's too bad the pgAdmin devs are unwilling to have this useful feature. It shouldn't be too hard to detect which query is "selected" based on cursor position in the file.
    – axiopisty
    Commented Oct 30, 2018 at 17:58
  • 2
    I love this : “We follow the pgAdmin 3 behaviour in this regard”. For the most part pgAdmin4 is inferior to pgAdmin3, but when it comes to suggesting a useful improvement, no, pgAdmin3’s fine …
    – Manngo
    Commented Aug 6, 2022 at 6:01
5

You can select your query in pgAdmin sql window and press F5. Same will work if you just put cursor on any line in your statement without actually selecting it but only if your statements are separated with semicolon.

5
  • 8
    Thanks. I'd prefer not having to select the query I want to execute. F5 seems to execute all the statements in the query editor. Commented Nov 7, 2015 at 16:41
  • Why? It's a shift home away
    – Tom V
    Commented Nov 7, 2015 at 16:59
  • @TomV You often need more than a shift home to select the query. E.g. multi-line queries. Commented Jul 3, 2016 at 19:24
  • Thank you! That helped! Commented Jan 15, 2021 at 22:48
  • 2
    @FranckDernoncourt Shift + Home + up arrow a few times? :/ it's 2023 and I still have to toil.
    – Musilix
    Commented Mar 15, 2023 at 2:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.