Write SQL with completion and inspections
此内容尚不支持你的语言。
In a console or a .sql file bound to a connection, the editor knows that connection’s schema. It
completes names, marks the ones that do not exist, warns about changes that would touch every row,
and keeps the statements you ran. Completion, inspections and query history: Works.
Before you start
Section titled “Before you start”A console or a .sql file bound to a connection:
Query and edit data.
Complete names
Section titled “Complete names”Press ⌃Space (CtrlSpace). After FROM, JOIN,
INTO and UPDATE, the list also opens by itself when you type the space.
| Where the caret is | What is offered |
|---|---|
After FROM, JOIN, INTO, UPDATE, TABLE |
Tables and views: the current schema first, then the others. System schemas only when you type their name. |
After alias. |
The columns of that table only. |
After JOIN |
Ready join clauses built from real foreign keys, with aliases, for example item i on m.sku = i.sku. |
| Elsewhere in a statement | The columns of the statement’s tables, then keywords. |
| Inside a string or a comment | Nothing. |
Each entry names its kind and schema at the right, for example table · public. Names that need
quotes are inserted with them. Before completing, the editor checks whether the schema changed (at
most every 2 seconds), so a table created in another program shows up without a refresh.
Functions, parameters and the columns of a WITH query are not completed yet.
Catch mistakes before you run
Section titled “Catch mistakes before you run”The editor checks each statement against the connection’s schema and underlines what it finds. The same problems are listed in the Problems tool window under “SQL”.
| Problem | Severity | Example message |
|---|---|---|
| Unknown table | error | unknown table custmer |
| Unknown column | error | unknown column emial in customer |
Change without WHERE |
warning | DELETE without WHERE removes every row of stock; add a WHERE clause (or WHERE true …) |
| Foreign key MySQL ignores | warning | MySQL ignores REFERENCES in the definition of column customer_id; … |
- On an unknown name, ⌥↩ (AltEnter) offers Replace
with
namefor up to three close matches. - Tables a script creates are known to its later statements, and the columns of a
WITHquery are checked against the query. - The warning about a change without
WHEREalso appears in orange after the statement. WriteWHERE truewhen you mean every row.
Type checks and ambiguous column names are not inspected yet.
Reuse a statement from the history
Section titled “Reuse a statement from the history”- Click History in the console bar, or press ⌥⌘E (CtrlAltE).
- Click a statement to insert it at the caret. Esc or a click outside closes the list.
The history is per connection and project, newest first, at most 500 entries; a repeated statement
appears once, failed ones in the error colour. It lives in your settings folder under
sql-history/ (folder mode 700, files mode 600), not in the project. Statements that contain a
password are not kept.
Rename a table or column across the project
Section titled “Rename a table or column across the project”Select the object in the Database tool window and press ⇧F6 (Rename…).
The dialog shows the statement for the database and the places in the project’s .sql files that
name the object. See Explore and change a schema.
| Action | Shortcut |
|---|---|
| BrowseConsole.History.Browse | ⌥⌘ECtrlAltE |
| Code › Code Completion | ⌃Space or ⌥⎋CtrlSpace |
| Code › Show Context Actions | ⌥↩AltEnter |
For agents
Section titled “For agents”The same completion, inspections and history are tools. They need the permission read-schema on
the connection (sql_history needs read-data, because past statements contain values).
complete_sqlComplete SQL at a cursor position using the connection's schema: tables after FROM/JOIN, after JOIN also ready join clauses (kindjoin) built from foreign keys to the tables already in the statement, columns of referenced tables or aliases, keywords (needs the read-schema permission).inspect_sqlInspect SQL against the connection's schema: unknown tables and columns, UPDATE/DELETE without WHERE, MySQL column-level REFERENCES that create no foreign key (needs the read-schema permission).sql_historyThe query history of a connection: the statements its consoles in the window ran, newest first, with time (seconds since 1970) and whether they succeeded.sql_refactorings_atWhat the SQL editor's refactorings find at a caret:objectis the table or column named there ({table, column}) as ⇧F6 would rename it, orobject_errorwith the reason (unknown, an alias, a column of several tables);expand_wildcardis the edit and the resulting SQL of "Expand column list" when the caret is on a*of a select list, else null;inlineis {name, edits, sql} of Inline on the WITH query named at the caret, elseinline_errorsays why (recursive, column list, MATERIALIZED, written to, unused, no WITH query) or both are null on no name.
No tool matches. Try fewer words, or .