Write and run queries in PG Studio
Write, edit, and execute queries in the SQL editor.
PG Studio is on by default. If it is off for your organization, you cannot run queries in the SQL editor. Instead, the editor shows a message to contact Aiven support. Aiven manages this control. To change it, contact the Aiven support team. See Manage PG Studio and AI features.
Write SQL manually
-
In the SQL editor, enter your query.
UseTabto autocompletePress the
Tabkey to autocomplete SQL keywords, table names, column names, and other database objects from your schema. When the autocomplete list is open, use the arrow keys to move between suggestions and pressEnterorTabto insert the selected suggestion. PressEscto dismiss autocomplete. -
Click Run, or press
Cmd+Enteron macOS orCtrl+Enteron Windows and Linux. -
View the results in the results panel.
The autocomplete feature helps you write queries faster by suggesting:
- SQL keywords and clauses:
SELECT,FROM,WHERE,JOIN - Table names from your selected schema
- Column names from tables in your query
- Database functions and operators
Run a single query
When the editor contains multiple SQL statements and you don't select any text, Run executes only the statement where your cursor is placed.
- In the SQL editor, place your cursor inside the query you want to run, without selecting any text.
- Click Run, or press
Cmd+Enteron macOS orCtrl+Enteron Windows and Linux. - View the results in the results panel.
This is useful for:
- Testing individual queries from a larger script
- Iterating on a single query while keeping other statements in context
- Testing each subquery independently before combining a complex query
- Verifying data in a specific table without executing setup or cleanup statements
Run multiple queries
You can write several SQL statements in the editor and run them all at once. Select the statements to run. The editor runs them sequentially and displays the results in separate tabs.
-
In the SQL editor, write your SQL statements:
SELECT count(*) FROM orders;SELECT * FROM users LIMIT 10; -
Select all the statements you want to run.
-
Click Run selected, or press
Cmd+Enteron macOS orCtrl+Enteron Windows and Linux. -
View the results in the results panel. When more than one statement runs, each result appears in its own tab labeled Query 1, Query 2, and so on:
- A red error indicator on a tab means the statement encountered an error. If a statement fails, execution stops and remaining statements are not run. Results from statements that completed before the error are preserved.
This is useful for:
- Running a sequence of setup, query, and cleanup statements in one go
- Executing a batch of related queries and comparing their results
- Validating multiple statements before saving or sharing a script
Execute queries
When you run a query, whether generated by the AI or written manually:
- The editor runs the query against the selected source database and schema.
- The results panel displays your query results. When running multiple statements, each result appears in its own tab.
Query execution limits
The editor applies these limits to query execution:
- Statement timeout: 30 seconds
- Lock timeout: 10 seconds
- Connection timeout: 10 seconds
- Result size: Large results are truncated. To see specific rows, add a
LIMITclause or refine your query. - Maximum statements per run: 10
- Rate limiting: 15 query executions per 10 seconds per user per service
- AI rate limiting: One AI request every two seconds per user per service
Browse tables while you write queries
While you write queries in the SQL editor, you can check table names in the list of schemas and tables for the selected source database. To change the list, select a different source database.
To preview table data or open the schema map, use Tables. See Explore your tables.
Related pages