The Query Tool is where you write and run SQL in pgAdmin 4. You type in an editor, press F5, and the result appears in a grid underneath.
Every screen on this page is real, from pgAdmin 4 9.19 with PostgreSQL 19 on macOS.
Step 1: Open the Query Tool
In the Object Explorer, click the database you want to work in, then click the Query Tool button: the second icon in the toolbar above the tree, a database with a small arrow:

A new tab opens with an empty editor, connected to that database.
Step 2: Type Your SQL
Type these two statements, one on each line:
SELECT 'Hello, pgAdmin!' AS greeting;
SELECT 2 + 3 AS total;

Step 3: Run Everything with F5
Press F5, or click the Execute script button, the triangle in the toolbar. With nothing selected, pgAdmin runs every statement in the editor, and Data Output shows the result of the last one:

Step 4: Run Only the Statement You Select
Select the first line with your mouse, then press F5 again. Only the selection runs:

This is handy when the editor holds several statements and you want the result of just one.
Step 5: Read an Error
When a statement has a mistake, pgAdmin switches to the Messages tab to show PostgreSQL’s error, and underlines the spot in the editor. Here, SELECT is misspelt:
SELEC 2 + 3 AS total;

The caret (^) under the line and Character: 1 point to where PostgreSQL stopped understanding the statement.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Expecting both results after running two statements | Data Output shows only the result of the last one. | Select one statement and press F5 to see its result. |
A misspelt keyword, such as SELEC | ERROR: syntax error at or near "SELEC" | Fix the word the caret points to, then run it again. |
FAQ
What happens to my SQL when I close the tab?
If the text has changed, pgAdmin asks first:

Click Don’t save to close the tab without keeping the SQL, or Cancel to go back to it.
Which key runs a query?
F5 runs the script, as pgAdmin’s list of keyboard shortcuts (opens in a new tab) shows.
Conclusion
Open the Query Tool on a database, type your SQL and press F5. With nothing selected it runs everything and shows the last result; select one statement to run just that, and read any errors in the Messages tab.
Additional Resources
- pgAdmin 4 documentation: Query Tool (opens in a new tab)
- pgAdmin 4 documentation: Query Tool Toolbar (opens in a new tab)
- pgAdmin 4 documentation: Keyboard Shortcuts (opens in a new tab)
Related
- PostgreSQL Tutorial — Part 3: pgAdmin 4 for Beginners
- How to Register a Server in pgAdmin 4
- How to Turn On Dark Mode in pgAdmin 4
- How to Change the Font Size in pgAdmin 4
Postgres, PostgreSQL and the Slonik Logo are trademarks or registered trademarks of the PostgreSQL Community Association of Canada, and used with their permission.
0 comments