Databases

The SQL editor is for the admin consoles, reporting screens and internal tools where people write SQL against your application's database. It reads PostgreSQL, SQL Server, MySQL and MariaDB, SQLite, Oracle and standard SQL the way each of those databases reads it. Give it your schema - tables and columns, or simply the rows of a query on information_schema.columns - and it completes table and column names, explains a name when you rest on it, and checks every statement as it is typed: a column that is not there (with the nearest one that is), UPDATE or DELETE without WHERE, = NULL, columns neither grouped nor aggregated, syntax from another database. Format lays a script out again and changes nothing it means.

The editor never connects to a database itself. Your page gives it a run function that hands the SQL to your own service, and the editor shows what comes back: a tab for each result set, the database's messages, an error marked at its place in the text, and a history of every run, with your snippets beside it. Ask for a plan and it reads PostgreSQL EXPLAIN, SQL Server showplan XML, MySQL EXPLAIN and SQLite EXPLAIN QUERY PLAN alike, points to the hot spots and compares the plan with the one before.

Try it with your own SQL scripts and query plans in confidence: they are opened by your browser, on your device. Nothing is uploaded, no copy reaches us or anyone else, and nothing is kept once you close this tab.

A reporting console, checked against its schema

Copperbeck Cycle Hire, a made-up bike hire company with six stations around the Lakes, keeps its rides in PostgreSQL. This is its Monday report as typed in a hurry, against an invented schema of four tables: a misspelt column, a comparison with NULL that never matches, a SELECT * and an UPDATE that would retire every bike. Find the mistakes, put them right, lay the script out and run it. There is no database on this page: its run function answers from a small set of invented rides kept in the page.

Find the mistakes Take the suggested column Put the rest right Format Run the takings Run all three The run history
Keyboard: in the text, Ctrl+Space offers the tables and columns that can go at the caret, Ctrl+Enter runs the statement at the caret (or the selection), Ctrl+Shift+Enter runs them all, Shift+Alt+F formats, F12 goes to where an alias is defined and Ctrl+K Ctrl+I explains the name at the caret. In the results, the arrow keys move through the grid, Enter opens a whole value and Ctrl+C copies a cell.

A slow query, before and after an index

Copperbeck's late-returns screen takes more than a second at the end of the month. Its plans here are invented PostgreSQL EXPLAIN (ANALYZE, FORMAT JSON) output, for an imagined table of 2.4 million rides. Find where the time goes, add the index, and explain the query again to compare the two plans. Then see an invented SQL Server showplan of another report, with the index SQL Server itself suggests.

Explain the slow query List the hot spots Add the index Explain it again A SQL Server plan Back to PostgreSQL
Keyboard: in the plan, Up and Down move between operations, Right opens a branch and Left closes it; the selected operation's details are shown beside the tree. Each hot spot is a button that takes you to its operation.