OriginChain docs
examples · sql

SQL examples

← All examples

13 SQL examples, each on its own page. Every example has the schema TOML it needs, a pre-seed insert, side-by-side cURL / Python / TypeScript / Go, the response shape, and notes on common mistakes.

8 work today. A few examples document features that are still on the roadmap (ORDER BY, HAVING, window functions, CTEs) - the page tells you what works now and how to work around the gap.

1
SELECT with projection
works today

Project specific columns from a single table. Read only the fields you need.

2
WHERE = on an indexed column
works today

Equality predicate. The planner promotes it to an IndexScan when an index covers the column.

3
WHERE col IN (...)
works today

Match against a small set of literal values. Folded into a disjunction over equalities.

4
WHERE col BETWEEN low AND high
works today

Range predicate on a numeric or string column. Inclusive on both bounds.

5
INNER JOIN - two tables
works today

Combine rows that have a match on both sides. Hash-join on the equality.

6
LEFT JOIN - keep unmatched left rows
works today

Every row from the left side, plus matches from the right (null if no match).

7
GROUP BY + COUNT / SUM / AVG / MIN / MAX
works today

Multiple aggregates in one pass. The hash aggregator buckets on the GROUP BY key.

8
LIMIT (ORDER BY is roadmap)
limited

LIMIT caps result count. ORDER BY through the SQL translator is on the roadmap.

9
Window functions (roadmap)
roadmap

ROW_NUMBER, RANK, LAG, LEAD - not yet supported. Compute rankings client-side.

10
Uncorrelated IN (SELECT ...)
works today

The supported subquery shape - inner SELECT doesn't reference outer. Correlated forms are not supported.

11
UPDATE via /sql (returns translation)
limited

/sql translates UPDATE into a typed payload but doesn't execute. For real writes, use /rows endpoints.

12
DELETE via /sql (returns translation)
limited

Same caveat as UPDATE - /sql returns a translation. Use /rows/:schema/:pk to actually delete.

13
WITH RECURSIVE (roadmap)
roadmap

Recursive CTEs are not yet supported. For hierarchy walks, use graph endpoints instead.