Write and run queries in PG Studio
Use the SQL editor in PG Studio to write, edit, and execute queries.
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.
-
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 selected SQL
When working with multiple SQL statements, the editor runs one query at a time. It runs the query where your cursor is placed.
- In the SQL editor, place your cursor in the query to run.
- Click Run selected next to the active query.
- 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
Execute queries
When you run a query, whether generated by the AI or written manually:
- The editor executes it.
- The results panel displays your query results.
- For write operations, PG Studio prompts you to confirm before execution as a safety measure.
PG Studio automatically detects the query type and applies appropriate safeguards.
Run write queries
You can execute data modification and data definition statements directly against your database.
To run a write query:
- In the SQL editor, enter your write query.
- Click Run.
- PG Studio detects the write operation and shows You are changing live data.
- Choose how to proceed:
- Run on production runs the query directly against the connected database.
- Test on a fork creates a fork so you can test the query without changing live data.
- Optional: Select Don't ask me again to skip this confirmation for future write queries on this service.
View and revert write query history
PG Studio keeps a change log of write queries you run. You can review changes and create a fork from a point in time before a specific write query.
To view the change log:
- In the SQL editor, click Change log. This option appears after you run at least one write query.
- In Change log, review each write query with its timestamp and query preview.
To create a fork from a point before a specific write query:
- Open Change log.
- Select the write query you want to roll back to.
- Click Create fork. PG Studio opens Create fork with a recovery timestamp set to the moment before that query ran.
Query execution limits
PG Studio applies these limits to query execution:
- Single-statement validation: PG Studio allows only one SQL statement per execution.
- Statement timeout: 30 seconds
- Lock timeout: 10 seconds
- Connection timeout: 10 seconds
- Maximum result size: 5,000 rows
- Rate limiting: Two query executions every two seconds per user per service; one AI request every two seconds per user per service.
Explore tables in the query editor
Use Tables in the query editor to browse your database tables and start to run SQL queries. The table list uses your selected source database and schema.
To use the Tables view:
- Open PG Studio.
- Select Tables in the query editor.
- Select a source database and schema.
- Select a table from the list.
When you open a table, PG Studio shows up to 100 rows.
From Tables, you can open a table tab and use it as a starting point for querying that table. For column definitions and relationships, use Open schema map.