DataGrip
 
Get DataGrip

Use database CLI tools

Last modified: 11 October 2024

Almost every database vendor has its own Command-Line Interface (CLI) tool. The following list shows you a couple of examples.

  • PostgreSQL: psql

  • Oracle: sqlplus (SQL Command Line for SQL*Plus)

  • MySQL: mysql

  • Microsoft SQL Server: sqlcmd

  • SQLite: sqlite3

In the majority of cases, these tools support two types of commands: standard and meta. Standard commands are SELECT, CREATE, UPDATE, and other ordinary SQL commands. Meta-commands use special syntax that is specific for every tool. For example, in SQLite, except for ordinary SQL statements, you can use dot-commands. These dot-commands are used to change the output format of queries or to execute certain prepackaged query statements. When you issue the dot-command, sqlite3 uses its own interpretation of the command and runs it on a database.

Other tools have different meta-commands. For example, sqlplus has DESCRIBE; psql has backslash directives like \dD; in sqlcmd, you can use :r Script.sql to load a script file. These commands are not standard SQL commands that your database would easily understand. They need to be translated. CLI tools do this translation.

DataGrip supports syntax highlighting for meta-commands but not the translation logic. It means that you can open an SQL script with meta-commands in the editor, but you need an external tool to run the script. By default, meta-commands are highlighted in green.

Dot-commands in the IDE