.NET

Writing SQL Queries

The most common kind of inner tab is the Query Tab, containing the following elements. Keyboard shortcuts below are the Windows/Linux defaults; on macOS, OmniDB's own shortcuts use Ctrl instead of Alt. All of them can be changed under Settings > Shortcuts.

A Query tab with the SQL editor, toolbar and results

The divider between the editor (with its toolbar) and the results can be dragged to give either more room.

Safety confirmation for destructive statements

Before running a statement that starts with DROP or TRUNCATE, or an UPDATE/DELETE without a WHERE clause, the Query Tab asks for confirmation (This statement is destructive and cannot be undone. Run it anyway?, or This statement has no WHERE clause and will affect ALL rows. Run it anyway?). This is a safety net against honest mistakes, not a permission system — it looks only at the beginning of the text (after comments).

Once executed, the tabs are also saved in OmniDB user database (title and contents), so the next time you open OmniDB, you will see them all open. Also, every command you execute in a Query Tab is saved to the command history of that connection.

SQL Autocomplete

The SQL editor has a feature that helps a lot when creating new queries: SQL code completion. Open the suggestions with Ctrl-Space (Option-Space on macOS). With this feature it is possible to autocomplete columns contained in a table referenced by an alias: type the alias, the character . and then open the autocomplete:

Autocomplete after a table alias

If the user does not start the autocomplete with the cursor close to a table alias, the component will show multiple categories of data. By typing in the filter textbox, elements in all categories will be filtered:

Autocomplete offering all categories

The autocomplete component is also able to identify some contextual information. For example, if you type a name of a schema, then type the character ., you will be able to filter among objects contained only in that schema:

Autocomplete after a schema name

After :: (a PostgreSQL type cast), only data types are offered. Choosing a keyword also adds what always follows it (for example a space after SELECT, or the opening parenthesis after COALESCE). Which categories are offered at all (keywords, databases, roles, tablespaces, schemas, extensions, tables, views, columns, functions, indexes) is set under Settings > Autocomplete.

Please note that for RDBMS other than PostgreSQL, the autocomplete component only works for table columns.