Skip to content
All products

SQL

Your application data.
Ready to query.

Filter, join and aggregate records in the same database as your vectors, relationships and search indexes.

From question to result.

Use SQL for the questions behind your application: which orders need attention, what customers bought and how activity changes over time.

Related tables. One query. A regional revenue report.Illustrative example

01 Related tables

shop.customers
idregion
c-01IN
c-02EU
shop.orders
CustomerCentsStatus
c-012,400paid
c-023,600paid
c-011,200paid
c-02900pending

02 One query

  1. JOINMatch customerscustomer_id = id
  2. WHEREKeep paid ordersstatus = 'paid'
  3. GROUP BYTotal by regionSUM(total_cents)

03 Application result

Paid revenueBy customer region
Illustrative query result, revenue in cents
RegionRevenue
IN3,600
EU3,600

Pending orders stay out of the total.

All amounts shown in cents.
  1. Define your tables

    Declare fields, primary keys and indexes. Write records through the SQL or row API, keeping related tables in the namespaces your application uses.

  2. Run and inspect

    Send a SQL statement, read the returned rows and use EXPLAIN to check how the engine scans, filters and joins your data.

OriginChainDB implements a documented SQL subset. Supported statements differ between the HTTP API and PostgreSQL wire access.

Try a join
In your application

A lookup.
A join.
A clearer picture.

Start with the records behind a screen. Join related tables when the question crosses them, then aggregate when you need a summary.

The revenue query uses the sample tables above. It matches each paid order to a customer and adds the amounts within each region.

Read supported SQL syntax
Query patternsSQL
01Join and aggregate

Paid revenue by region

SELECT c.region,
  SUM(o.total_cents)
    AS revenue_cents
FROM shop.orders o
JOIN shop.customers c
  ON o.customer_id = c.id
WHERE o.status = 'paid'
GROUP BY c.region;
02Find the records you need

The latest paid orders

SELECT id, customer_id,
  total_cents
FROM shop.orders
WHERE status = 'paid'
ORDER BY placed_ms DESC
LIMIT 20;
03Bind application input

Pass a customer ID as $1

SELECT id, total_cents
FROM shop.orders
WHERE customer_id = $1
LIMIT 20;

Send the value for $1 in the request's params array.

Understand the work

Inspect before you tune.

A query plan shows how an answer is assembled. Use it to make a deliberate change, then check what that change achieved.

  1. 01EXPLAIN

    Read the plan

    Check whether the engine scans the table or uses an index. Follow the filters, joins and aggregation stages.

  2. 02WHERE + index

    Narrow the input

    Filter on an indexed field where possible. Return the columns you need and add a limit to exploratory queries.

  3. 03EXPLAIN ANALYZE

    Measure the execution

    Run the query with execution details, compare the work performed and keep changes that help your workload.

Keep the whole query in view. Sorting can process the full input before a limit applies. Narrow that input first when working with large tables.

Explore query plans

Why SQL on OriginChainDB?

Familiar query patterns

Build application screens and reports with filtering, sorting, joins and aggregates. Bind user input through positional parameters.

Explore the SQL reference

Records behind every result

Use shared record IDs to retrieve the business fields behind a vector match, graph connection or full-text search hit.

See the data models

Execution you can inspect

Review query plans and index use before tuning a query, with EXPLAIN available through the same SQL endpoint.

Inspect a query

Put it to work.

Find the right SQL pattern

Check supported statements, response formats and query limits before adding a new query to your application.

SQL reference

Review PostgreSQL behavior

Check current transaction behavior, error handling and known differences on dedicated deployments.

PostgreSQL compatibility

Connect a database client

Use an enabled PostgreSQL wire endpoint. Check its preview scope and the read-only rules for database-user sessions.

Client connection guide

Build with OriginChainDB.