Query with Neon's SQL Editor
Query your database from the Neon Console using the Neon SQL Editor
The Neon SQL Editor allows you to run queries on your Neon databases directly from the Neon Console. In addition, the editor keeps a query history, permits saving queries, and provides Explain and Analyze features.
To use the SQL Editor:
- Navigate to the Neon console.
- Select your project.
- Select SQL Editor.
- Select a branch and database.
- Enter a query into the editor and click Run to view the results.
You can use the following query to try the SQL Editor. The query creates a table, adds data, and retrieves the data from the table.
CREATE TABLE playing_with_neon(id SERIAL PRIMARY KEY, name TEXT NOT NULL, value REAL);
INSERT INTO playing_with_neon(name, value)
SELECT LEFT(md5(i::TEXT), 10), random() FROM generate_series(1, 10) s(i);
SELECT * FROM playing_with_neon;
Running multiple query statements at once returns a separate result set for each statement. The result sets are displayed in separate tabs, numbered in order of execution, as shown above.
To clear the editor, click New Query.
tip
When querying objects such as tables and columns with upper case letters in their name, remember to enclose the identifier name in quotes. For example: SELECT * FROM "Company"
. PostgreSQL folds identifier names to lower case unless they are quoted. The same applies when creating objects in PostgreSQL. For example, CREATE TABLE DEPARTMENT(id INT)
creates a table named department
in PostgreSQL. For more information about how quoted and unquoted identifiers are treated by PostgreSQL, see Identifiers and Key Words, in the PostgreSQL documentation.
Save your queries
The SQL Editor allows you to save your queries.
To save a query:
- Enter the query into the editor.
- Click Save to open the SAVE QUERY dialog.
- Enter a name for the query and click Save.
The query is added to the Saved list in the left pane of the SQL Editor. You can rerun a query by selecting it from the Saved list.
You can rename or delete a saved query by selecting Rename or Delete from the the kebab menu associated with the saved query.
View the query history
The SQL Editor maintains a query history for the project. To view your query history, select History in the left pane of the SQL Editor. You can click an item in the History list to view the query that was run.
Explain and Analyze
The Neon SQL Editor provides Explain and Analyze features.
- The Explain feature runs the specified query with the PostgreSQL EXPLAIN command, which returns the execution plan for the query. The Explain feature only returns a plan with estimates. It does not execute the query.
- The Analyze feature runs the specified query with EXPLAIN ANALYZE. The
ANALYZE
parameter causes the query to be executed and returns actual row counts and run times for plan nodes along with theEXPLAIN
estimates.
Understanding the information provided by the Explain and Analyze features requires familiarity with PostgreSQL's EXPLAIN command and its ANALYZE
parameter. Refer to the EXPLAIN documentation and the Using EXPLAIN topic in the PostgreSQL documentation.
Need help?
Send a request to support@neon.tech, or join the Neon community forum.