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.

11 work today. ORDER BY, HAVING, window functions, and UPDATE via /sql all execute now. A few remain limited or on the roadmap (DELETE via /sql translates only, recursive CTEs, UNION) - 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
ORDER BY + LIMIT / OFFSET
works today

ORDER BY (asc/desc), LIMIT and OFFSET all execute through the SQL translator today.

9
Window functions
works today

ROW_NUMBER and RANK with OVER (PARTITION BY ... ORDER BY) execute today. Explicit ROWS frames are still roadmap.

10
Uncorrelated IN (SELECT ...)
works today

Uncorrelated and correlated subqueries both execute - IN (SELECT), EXISTS / NOT EXISTS, and scalar forms.

11
UPDATE via /sql
works today

UPDATE executes against the engine and returns rows_affected. (Earlier builds only translated.)

12
DELETE via /sql (translation)
limited

DELETE through /sql returns the translated delete (the pk it would remove) but does NOT execute it today.

13
WITH RECURSIVE (roadmap)
roadmap

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