Write and check SQL

The editor helps you write a query faster. It suggests names, offers AI suggestions, checks the syntax, formats the text and rewrites parts of the query. Use these tools while you write, before you run the query.

Get suggestions while you type

  1. Start typing in the editor; the list opens under the cursor. It offers keywords, functions, databases, tables and columns of the role selected in the Role selector. It also offers CTE names, the settings after SETTINGS and the parameters you have added.
  2. Press Ctrl+Space to open the list at any time. The keyboard shortcuts window lists this key as Show suggestions.
  3. After a dot the list opens at once: a database name with a dot lists its tables, and a table, alias or CTE name with a dot lists that source's columns.
  4. Press Enter or Tab to insert the highlighted item.

Hover over a function name that is followed by ( to read its documentation, and type ( or , inside a call to see the parameters it takes.

In a query longer than 50,000 characters, the list stops appearing. In some smaller SQL boxes in other screens, it offers keywords and snippets only. The Autocomplete reference explains both.

Use AI suggestions

DataMind's AI, Kartlos, suggests the next part of your query. You see a suggestion in two places:

The suggestion uses the tables of the selected role and your two latest runs of this console. A failed run is included with its error message, so the suggestion can help you fix it. For each suggestion, the editor reads up to 8 tables, up to 120 columns from each, and an 8,000-character window of the query around the cursor.

To turn suggestions off, click the sparkle button in the toolbar. Hover over it to see AI suggestions on - click to disable or AI suggestions off - click to enable. The setting applies to every tab in this browser.

How suggestions behave

Check the syntax

About a second after you stop typing, the editor checks the statement at the cursor. While it waits, the toolbar shows Pending…. While the check runs, it shows Checking…. If the cursor is not inside a statement, the check uses the first statement in the console. Placeholders like {name:Type} are set aside while the check runs, so they do not cause errors.

If the syntax is wrong:

  1. Look for the alert icon in the toolbar.
  2. Hover over the icon to read Syntax error detected, followed by the detail from the database.
  3. Find the red underline in the SQL. It starts where the error begins. For a quote that is never closed, it starts at the opening quote.
Important

The syntax check only reads the SQL. It does not check whether tables and columns exist. Unknown tables and columns are reported when you run the query.

Format SQL

  1. Click the wrap-text icon in the toolbar, or press Ctrl+Shift+F. Its tooltip reads Format SQL (Ctrl+Shift+F).
  2. While the text is being formatted, the tooltip reads Formatting SQL….

Formatting applies to the whole console. Each statement separated by a semicolon is formatted on its own. Formatting changes the layout only: indents of 4 spaces, line breaks and keyword case. Keywords are shown in upper case, and names and aliases keep their spelling. Lines wrap at around 100 characters. If a change would alter anything else in the query, the result is discarded and your text stays as it was. Press Ctrl+Z to undo a format.

Rewrite SQL with intentions

Put the cursor where you want to rewrite the query and press Alt+Enter. A list opens with the rewrites that apply at that point. Press ↑ or ↓ to choose, Enter to apply and Esc to close the list. Any other key also closes it. If no rewrite applies, nothing opens. Press Ctrl+Z to undo a rewrite.

RewriteWhat it does
Expand column listReplaces * with the columns of the tables in FROM and JOIN.
Extract subquery as CTEMoves the subquery at the cursor into a WITH clause.
Inline CTE with the CTE's namePuts the body of the CTE where it is used and removes its definition.
Convert statement to CTETurns the statement into a WITH clause and selects from it.
Convert statement to subqueryWraps the statement as a subquery in FROM.
Add commasAdds a comma after each selected value, except the last.
Add quotes & commasDoes the same as Add commas, and wraps unquoted values in single quotes.

Some rewrites appear only in certain cases:

Open a table from the query

Put the cursor on a table name and press Ctrl+B to open the table's popup in the Lake or Warehouse. The shortcuts window lists this as Open table in Lake/WH. If the name is written in quotes, the whole quoted name is used, so a name with spaces opens as itself. Without a table name at the cursor, the editor shows No table name at cursor.

Permissions

To see AI suggestions, your role needs one of these permissions:

For the shortcut keys used on this page, see Editor reference: shortcuts and tools.

Questions, answered

Why does autocomplete not suggest a table I know exists?

Check the Role selector. Suggestions come only from the databases of the selected role (see SQL dialect and data scope), so pick the role that can read the table. If the table is new, click the refresh button in the Database Explorer header. Its tooltip reads Refresh Schema. See Database Explorer.

How do I turn off the grey AI text?

Click the sparkle button in the toolbar. The setting is kept in this browser, in every tab. Your choice does not follow you to another browser.

Why do I never see AI suggestions?

Check that the sparkle button is on, keep typing and stop for about three seconds. Your role also needs one of the permissions listed above.

The editor says my SQL is valid, but the run fails because a table is unknown. Why?

The syntax check only reads the SQL. It does not look up tables or columns, so those errors appear only when you run the query. Check the table name and run the query again. For other messages, see Editor troubleshooting.

Can I undo a format or a rewrite?

Yes. Press Ctrl+Z after a format or a rewrite to go back one step. Press Ctrl+Y to redo.

Why did Format SQL leave my query unchanged?

Formatting changes layout only: indents, line breaks and keyword case. If the formatter cannot do that without changing anything else in the query, it discards the result and your text stays exactly as it was. Nothing is broken; the query is as you wrote it.

How do I turn a list of IDs into an IN list?

Paste one value per line and select those lines. Press Alt+Enter and choose Add commas. If the values are not quoted, choose Add quotes & commas to wrap them in single quotes as well. Add the parentheses around the list yourself.

How do I replace SELECT * with real column names?

Put the cursor after the *, press Ctrl+Space and choose Expand column list. You can also press Alt+Enter and choose the same item. It works only when the editor can find the columns of every table in the query.

Why does Ctrl+B say "No table name at cursor"?

The cursor is not on a table name. Click the table name itself, inside its quotes if it has them, and press Ctrl+B again.