Skip to Content
Querying & SQL

Querying & SQL

The CLI is SQL-first: if a statement works through /v1/api/sql, send it unchanged via kalam --command, kalam --file, or the interactive shell.

Execution options

OptionDescription
-c, --command <SQL>Execute one statement and exit.
-f, --file <PATH>Execute SQL from file and exit.
--format <table|json|csv>Output format (default table).
--jsonShorthand for --format json.
--csvShorthand for --format csv.
--no-colorDisable ANSI colors.
--no-spinnerDisable spinner animations.
--loading-threshold-ms <MS>Spinner threshold in milliseconds.
BASH
kalam --command "SELECT * FROM system.tables LIMIT 5;"kalam --command "SELECT * FROM system.tables LIMIT 5;" --jsonkalam --file ./setup.sql --csvkalam --url kalam.masky.app --command "SELECT 1;"

Common patterns

BASH
# Read system metadatakalam -c "SELECT * FROM system.tables ORDER BY namespace_id, table_name LIMIT 20;" # DDL / DMLkalam -c "CREATE NAMESPACE chat;"kalam -c "CREATE TABLE chat.messages (id BIGINT PRIMARY KEY, body TEXT) WITH (TYPE='USER');"kalam -c "INSERT INTO chat.messages (id, body) VALUES (1, 'hello');" # Run a whole SQL filekalam -f ./migrations/001-init.sql

Namespace state in interactive mode

Namespace switching is SQL, not a backslash command:

SQL
USE NAMESPACE chat;SELECT * FROM messages ORDER BY id DESC LIMIT 20;\flush table messages

After USE NAMESPACE chat, SET NAMESPACE chat, or USE chat, the CLI stores chat locally and sends it as namespace_id on later requests. Unqualified table names resolve to chat.<table> until you switch again. The prompt shows the active namespace as ns:<name>.

In table format, results end with row count and footer metadata:

TEXT
(50 rows)As: aliceTook: 2.146 ms
  • As: — effective user (includes EXECUTE AS and \as)
  • Took: — server-reported execution time in milliseconds

Interactive formatting

CommandDescription
\dt, \tablesList tables.
\d <table>, \describe <table>Describe columns (<table> or <namespace.table>).
\format table|json|csvChange output format for the session.
\refresh-tables, \refreshRefresh autocomplete table metadata.
Last updated on