Skip to Content
SQL ReferenceQuery Data (SELECT & JOIN)

Query Data (SELECT & JOIN)

Use this page for query-only SQL patterns in KalamDB.

KalamDB supports the DataFusion SELECT query surface. For advanced query syntax and planner behavior, use the DataFusion SQL docs as the primary reference:

Basic SELECT

sql snippetSQL
SELECT <columns>FROM [<namespace>.]<table_name>[WHERE <condition>][ORDER BY <expr> [ASC|DESC]][LIMIT <n>];

Example:

sql snippetSQL
SELECT id, sender, content, created_atFROM chat.messagesWHERE conversation_id = 42ORDER BY created_at DESCLIMIT 50;

Filtering, Grouping, and Aggregation

sql snippetSQL
SELECT sender, COUNT(*) AS message_countFROM chat.messagesWHERE conversation_id = 42GROUP BY senderHAVING COUNT(*) >= 10ORDER BY message_count DESC;

JOIN Support

KalamDB supports standard DataFusion join patterns, including:

  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • FULL JOIN
  • CROSS JOIN
  • JOIN ... USING (...)

Example (INNER JOIN):

sql snippetSQL
SELECT m.id, m.content, u.emailFROM chat.messages mINNER JOIN system.users u ON m.user_id = u.user_idWHERE m.conversation_id = 42;

Example (LEFT JOIN):

sql snippetSQL
SELECT c.id, c.title, m.contentFROM chat.conversations cLEFT JOIN chat.messages m ON c.id = m.conversation_idORDER BY c.id;

Subqueries and CTEs

Common DataFusion query constructs are supported, including subqueries and CTEs.

sql snippetSQL
WITH ranked AS (  SELECT    sender,    COUNT(*) AS total_messages  FROM chat.messages  GROUP BY sender)SELECT *FROM rankedWHERE total_messages >= 100ORDER BY total_messages DESC;

Set Operations

You can use DataFusion set operations such as UNION and UNION ALL.

sql snippetSQL
SELECT sender FROM chat.messages_2025UNION ALLSELECT sender FROM chat.messages_2026;

PostgreSQL-style JSON Queries

JSON and JSONB columns can be queried with the same common extraction syntax PostgreSQL users already know.

sql snippetSQL
SELECT  doc->>'status' AS status,  doc->'items'->0 AS first_itemFROM app.ordersWHERE doc->>'status' = 'paid'  AND doc ? 'customer_id';

Use -> when you want a JSON value, ->> when you want text, and ? when you only need to test key existence.

KalamDB also exposes DataFusion JSON helpers such as json_get, json_as_text, json_length, and json_object_keys for function-style access. For the full JSON function list and current operator coverage, see Built-in Functions.

Advanced Query Reference

For advanced SELECT features, rely on DataFusion SQL documentation:

Last updated on