---
title: "corasql interpreter"
description: "Use corasql, the CoraDB command-line SQL interpreter: interactive, batch and standalone modes, its options and session commands."
url: "https://www.coradb.ai/manual/corasql.html"
markdown_url: "https://www.coradb.ai/manual/markdown/corasql.md"
product: "CoraDB"
version: "1.0"
keywords: "corasql, coradb command line, coradb sql client, corasql options, corasql session commands, corasql batch mode, corasql -c, corasql -i, corasql standalone mode, ;schema, ;plan, ;trace"
---

# corasql interpreter

corasql is the command-line SQL client installed with CoraDB. With it you can:

- Run SQL and graph queries interactively or from script files, and save the results to files;
- Inspect schemas, triggers, query plans, traces, locks and statistics;
- Change system parameters for the session or, as **DBA**, for the server;
- Run administrative SQL directly on database files in standalone mode, without a running server.

## Execution modes

| Mode | Description |
|---|---|
| Interactive | You type statements at the `corasql>` prompt and see the results; the default. |
| Batch | Statements are read from a file (**-i**) or the command line (**-c**). |
| Client-server (**-C**) | corasql connects to a running database server; the default. Many clients can work at the same time. |
| Standalone (**-S**) | corasql opens the database files itself, without a server. Only one user can use the database, which suits administrative tasks. |
| System administration (**--sysadm**) | For **DBA**: allows one corasql connection even when the server already has **max_clients** connections, for example to run a checkpoint or end transactions. |

## Starting corasql

```text
corasql [options] database_name[@host]
```

```bash
corasql -u dba e-commerce
```

```text
CoraDB SQL Interpreter

Type `;help' for help messages.

corasql> SELECT COUNT(*) FROM orders WHERE YEAR(order_date) = 2025;

=== <Result of SELECT Command in Line 1> ===

     count(*)
=============
          786

1 row selected. (0.004193 sec) Committed.

corasql> ;exit
```

- End each SQL statement with a semicolon. Several statements can be written on one line.
- Without **-u**, corasql logs in as **PUBLIC**. If the user has a password and **-p** is not given, corasql prompts for it.
- By default every statement is committed automatically (see **--no-auto-commit** and `;autocommit`).

To connect to a database on another host, add `@host` to the database name. The CoraDB version and the master process port (`coradb_port_id`) on both hosts must be the same:

```bash
corasql -C -u dba e-commerce@192.168.1.3
```

## corasql options

Run `corasql` without a database name to list the options:

```text
usage: corasql [OPTION] database-name[@host]

valid options:
  -S, --SA-mode                standalone mode execution
  -C, --CS-mode                client-server mode execution
  -u, --user=ARG               alternate user name
  -p, --password=ARG           password string, give "" for none
  -e, --error-continue         don't exit on statement error
  -i, --input-file=ARG         input-file-name
  -o, --output-file=ARG        output-file-name
  -s, --single-line            single line oriented execution
  -c, --command=ARG            corasql-commands
  -l, --line-output            display each value in a line
  -r, --read-only              read-only mode
  -t, --plain-output           display results in a script-friendly format (only works with -c and -i)
  -q, --query-output           display results in a query-friendly format (only work with -c and -i)
  -d, --loaddb-output          display results in a loaddb-friendly format (only work with -c and -i)
  -N, --skip-column-names      do not display column names in results (only works with -c and -i)
      --string-width           display each column which is a string type in this width
      --no-auto-commit         disable auto commit mode execution
      --no-pager               do not use pager
      --no-single-line         turn off single line oriented execution
      --no-trigger-action      disable trigger action
      --delimiter=ARG          delimiter between columns (only work with -q)
      --enclosure=ARG          enclosure for result string (only work with -q)
```

**-S, --SA-mode**

Opens the database in standalone mode, without a server. No other corasql or utility can use the database at the same time. If neither **-S** nor **-C** is given, **-C** is used.

```bash
corasql -S -u dba e-commerce
```

**-C, --CS-mode**

Connects to the database server (client-server mode), the default. Errors that occur during the session are logged in `corasql.err` in the current directory, also when the server is on another host.

**-u, --user=ARG**

The user to log in as; **PUBLIC** if omitted. An unknown user name ends corasql with an error.

**-p, --password=ARG**

The password. In batch mode, where corasql cannot prompt, give it with **-p**; use `-p ""` for a user without password.

```bash
corasql -u dba -p "" e-commerce
```

**-i, --input-file=ARG**

Runs the statements in a file (batch mode) instead of reading them interactively.

```bash
corasql -u dba -i monthly_report.sql e-commerce
```

**-o, --output-file=ARG**

Writes the results to a file instead of the screen.

```bash
corasql -u dba -i monthly_report.sql -o monthly_report.txt e-commerce
```

**-s, --single-line**

Executes the statements of an input file one at a time, each ending with a semicolon, which needs less memory than reading the whole file first. Single-line execution is also the default in interactive mode; see **--no-single-line**.

```bash
corasql -u dba -s -i load_orders.sql e-commerce
```

**-c, --command=ARG**

Runs one or more statements, separated by semicolons, given on the command line:

```bash
corasql -u dba -c "SELECT COUNT(*) FROM orders; SELECT COUNT(*) FROM order_items" e-commerce
```

**-l, --line-output**

Displays each column of a result row on its own line (see `;line-output`).

**-e, --error-continue**

Continues with the next statement when a statement fails with a semantic or runtime error. A syntax error still stops the execution.

```text
$ corasql -u dba -e e-commerce

corasql> SELECT * FROM no_such_table; SELECT id, name FROM product WHERE id = 1618;

ERROR: Unknown class "no_such_table".

=== <Result of SELECT Command in Line 1> ===

           id  name
==================================
         1618  'Gobi HeatTec Tee'

1 row selected. (0.003127 sec) Committed.
```

**-r, --read-only**

Connects in read-only mode: queries are allowed, statements that change data or the schema are not.

**-t, --plain-output**

With **-c** or **-i**: prints only column names and values, separated by tabs, one row per line. Tabs, line feeds and backslashes inside values are written as `\t`, `\n` and `\\`. Ignored together with **-l**.

```text
$ corasql -u dba -c "SELECT id, name, unit_price FROM product WHERE id IN (1157, 1618, 1619) ORDER BY id" -t e-commerce

id	name	unit_price
1157	Go-Get'r Pushup Grips	19.00
1618	Gobi HeatTec Tee	29.00
1619	Hero Hoodie	54.00
```

**-q, --query-output**

With **-c** or **-i**: prints column names and values separated by commas (or the **--delimiter** character), with all non-numeric values enclosed in single quotes (or the **--enclosure** character), ready to be used in **INSERT** statements. With single quotes as enclosure, quotes inside values are doubled. Ignored together with **-l**.

```text
$ corasql -u dba -c "SELECT id, name, unit_price FROM product WHERE id IN (1157, 1618, 1619) ORDER BY id" -q e-commerce

id,name,unit_price
1157,'Go-Get''r Pushup Grips',19.00
1618,'Gobi HeatTec Tee',29.00
1619,'Hero Hoodie',54.00
```

```text
$ corasql -u dba -c "SELECT id, name, unit_price FROM product WHERE id IN (1157, 1618, 1619) ORDER BY id" -q --enclosure='"' e-commerce

id,name,unit_price
1157,"Go-Get'r Pushup Grips",19.00
1618,"Gobi HeatTec Tee",29.00
1619,"Hero Hoodie",54.00
```

**-d, --loaddb-output**

With **-c** or **-i**: prints the result in the input format of [loaddb](https://www.coradb.ai/manual/admin/admin_unload.html#loaddb): a `%class` line followed by one line per row, values separated by spaces, non-numeric values in single quotes (quotes inside doubled), **ENUM** values as their index. Ignored together with **-l**.

```text
$ corasql -u dba -c "SELECT id, name, unit_price FROM product WHERE id IN (1157, 1618, 1619) ORDER BY id" -d e-commerce

%class [ ] ([id] [name] [unit_price])
1157 'Go-Get''r Pushup Grips' 19.00
1618 'Gobi HeatTec Tee' 29.00
1619 'Hero Hoodie' 54.00
```

**-N, --skip-column-names**

With **-c** or **-i**: omits the column names, usually together with **-t**, **-q** or **-d**. Ignored together with **-l**.

```text
$ corasql -u dba -c "SELECT id, name FROM product WHERE id IN (1618, 1619) ORDER BY id" -t -N e-commerce

1618	Gobi HeatTec Tee
1619	Hero Hoodie
```

**--string-width=ARG**

Displays string columns truncated to this width (see `;string-width`).

**--no-auto-commit**

Turns off auto-commit: statements stay in the open transaction until `COMMIT` or `;commit`. The same as `;autocommit off` in the session.

**--no-pager**

Prints results all at once instead of page by page.

**--no-single-line**

Collects statements in the query buffer instead of executing each one at once; run the buffer with `;run` or `;xrun`.

**--sysadm**

System administration mode, used together with `-u dba`:

```bash
corasql -u dba --sysadm e-commerce
```

**--no-trigger-action**

Disables the [triggers](https://www.coradb.ai/manual/sql/trigger.html) for the statements of this session.

**--delimiter=ARG**

With **-q**: the character that separates columns, instead of a comma. Only the first character is used; escapes such as `\t` are accepted.

**--enclosure=ARG**

With **-q**: the character that encloses non-numeric values, instead of a single quote. Only the first character is used.

## Session commands

Besides SQL, corasql accepts *session commands*, which start with a semicolon. They are not case-sensitive, and each can be abbreviated to the letters shown in uppercase below (`;sch` for `;SChema`). `;help` lists them:

```text
   ;REAd   [<file-name>]        - read a file into command buffer.
   ;Write  [<file-name>]        - (over)write command buffer into a file.
   ;APpend [<file-name>]        - append command buffer into a file.
   ;PRINT                       - print command buffer.
   ;SHELL                       - invoke shell.
   ;CD                          - change current working directory.
   ;EXit                        - exit program.

   ;CLear                       - clear command buffer.
   ;EDIT                        - invoke system editor with command buffer.
   ;LISt                        - display the content of command buffer.

   ;RUn                         - execute sql in command buffer.
   ;Xrun                        - execute sql in command buffer,
                                  and clear the command buffer.
   ;COMmit                      - commit the current transaction.
   ;ROllback                    - roll back the current transaction.
   ;AUtocommit [ON|OFF]         - enable/disable auto commit mode.
   ;REStart                     - restart database.

   ;SHELL_Cmd    [shell-cmd]    - set default shell, editor, print and pager
   ;EDITOR_Cmd   [editor-cmd]     command to new one, or display the current
   ;PRINT_Cmd    [print-cmd]      one, respectively.
   ;PAger_cmd    [pager-cmd]

   ;DATE                        - display the local time, date.
   ;DATAbase                    - display the name of database being accessed.
   ;SChema class-name           - display schema information of a class.
   ;TRIgger [`*'|trigger-name]  - display trigger definition.
   ;Get system_parameter        - get the value of a system parameter.
   ;SEt system_parameter=value  - set the value of a system parameter.
   ;STring-width [width]        - set width that each column which is a string type is displayed.
   ;COLumn-width [name]=[width] - set width that a specific column is displayed.
   ;PLan [simple/detail/off]    - show query execution plan.
   ;Info <command>              - display internal information.
   ;TIme [ON/OFF]               - enable/disable to display the query
                                  execution time.
   ;LINe-output [ON/OFF]        - enable/disable to display each value in a line
   ;HISTORYList                 - display list of the executed queries.
   ;HISTORYRead <history_num>   - read entry on the history number into command buffer.
   ;TRAce [ON/OFF] [text/json]  - enable/disable sql auto trace.
   ;HElp                        - display this help message.
```

The *query buffer* holds the statements typed so far. In the default single-line mode a statement runs as soon as it ends with a semicolon; with **--no-single-line**, statements accumulate in the buffer until `;run` or `;xrun`.

### Files and the shell

| Command | Effect |
|---|---|
| `;REAd file` | Reads a file into the query buffer; `;LISt` shows it and `;RUn` executes it |
| `;Write file` | Writes the query buffer to a file, replacing it |
| `;APpend file` | Appends the query buffer to a file |
| `;PRINT` | Prints the query buffer |
| `;SHELL` | Starts a shell; `exit` returns to corasql |
| `;CD dir` | Changes the current working directory |
| `;SHELL_Cmd cmd`, `;PAger_cmd cmd`, `;PRINT_Cmd cmd`, `;EDITOR_Cmd cmd` | Set the shell, pager, print and editor commands (shown without an argument) |
| `;EDIT` | Edits the query buffer in the editor (`vi` on Linux, Notepad on Windows by default) |
| `;EXit` | Leaves corasql |

```text
corasql> ;read top_customers.sql
The file has been read into the command buffer.
corasql> ;list
SELECT customer_id, COUNT(*) AS orders FROM orders GROUP BY customer_id ORDER BY 2 DESC LIMIT 3;
corasql> ;run
```

```text
corasql> ;pager_cmd less -S
```

### Query buffer and transactions

| Command | Effect |
|---|---|
| `;CLear` | Empties the query buffer |
| `;LISt` | Shows the query buffer |
| `;RUn` | Executes the query buffer |
| `;Xrun` | Executes the query buffer and empties it |
| `;COMmit` | Commits the current transaction |
| `;ROllback` | Rolls back the current transaction |
| `;AUtocommit [ON\|OFF]` | Turns auto-commit on or off, or shows the setting |
| `;REStart` | Reconnects to the database |
| `;CHeckpoint` | (**DBA**, `--sysadm`) writes all dirty pages of the data buffer to disk |
| `;Killtran` | (**DBA**, `--sysadm`) shows the transactions, or ends one |

A checkpoint flushes the dirty pages of the buffer to disk; its regular interval is set by [checkpoint_interval](https://www.coradb.ai/manual/admin/config_logging.html#checkpoint_interval) and related parameters, which can be changed with `;set`.

### Information

| Command | Shows |
|---|---|
| `;DATE` | The current local date and time |
| `;DATAbase` | The database and host corasql is connected to, for example `e-commerce@dbhost` |
| `;SChema table` | The columns, types, constraints and indexes of a table |
| `;TRIgger [* \| name]` | The definition of a trigger, or all trigger names |
| `;Info command` | Internal information; see below |
| `;HISTORYList` | The statements run in this session, numbered |
| `;HISTORYRead n` | Reads statement *n* of the history into the query buffer |

`;Info` accepts:

| `;Info` argument | Shows |
|---|---|
| `schema [table]` | Schema information |
| `trigger [name]` | Trigger information |
| `deferred` | Deferred triggers waiting to run |
| `workspace` | The client workspace |
| `lock` | The lock table (client-server mode) |
| `stats table` | Statistics of a table |
| `trantable` | The transaction table |
| `logstat` | Log information |
| `csstat` | Critical sections |


### Parameters, plans and traces

| Command | Effect |
|---|---|
| `;Get parameter` | Shows the value of a system parameter |
| `;SEt parameter=value` | Changes a system parameter; server parameters require **DBA** |
| `;PLan [simple \| detail \| off]` | Prints the query plan of each statement: **simple** is optimization level 257, **detail** is 513 |
| `;TRAce [ON \| OFF] [text \| json]` | Prints the [query profile](https://www.coradb.ai/manual/sql/tuning_plan.html#query-profiling) after each result, as **SHOW TRACE** would |
| `;TIme [ON \| OFF]` | Shows the execution time of each statement (on by default) |

```text
corasql> ;set block_ddl_statement=1
=== Set Param Input ===
block_ddl_statement=1
```

Which parameters can be changed this way, and whether a change affects the session or the server, is listed in [System parameters](https://www.coradb.ai/manual/admin/config.html). `;trace` is not available in standalone mode. The execution time of a **SELECT** includes printing its rows; use **--no-pager** when timing large results.

### Output format

| Command | Effect |
|---|---|
| `;LINe-output [ON \| OFF]` | Shows each column of a row on its own line |
| `;STring-width [n]` | Truncates string and bit string columns to *n* characters; 0 shows them in full; without *n*, shows the setting |
| `;COLumn-width [name]=[n]` | Sets the display width of one column, whatever its type; without arguments, shows the settings |

```text
corasql> ;line-output on
corasql> SELECT id, name, unit_price, units_in_stock FROM product WHERE id IN (1618, 1619);

=== <Result of SELECT Command in Line 1> ===

<00001> id            : 1618
        name          : 'Gobi HeatTec Tee'
        unit_price    : 29.00
        units_in_stock: 22
<00002> id            : 1619
        name          : 'Hero Hoodie'
        unit_price    : 54.00
        units_in_stock: 76

2 rows selected. (0.003512 sec) Committed.
```

```text
corasql> ;string-width 5
corasql> SELECT name FROM product WHERE id IN (1618, 1619);
  'Gobi '
  'Hero '
corasql> ;string-width
STRING-WIDTH : 5
```


### Execution statistics

When the server parameter **communication_histogram** is `yes`, a **DBA** can collect the server statistics of the current connection:

| Command | Effect |
|---|---|
| `;.hist on` / `;.hist off` | Starts / stops collecting |
| `;.dump_hist` | Prints the statistics collected so far |
| `;.x_hist` | Prints them and resets the counters |
| `;.clear_hist` | Resets the counters |

The output lists client requests and counters such as page fetches, lock requests, commits, index operations and scans, the same items that [coradb statdump](https://www.coradb.ai/manual/admin/admin_statdump.html#statdump) reports for the whole server.
