OriginChainDB
SQL

Prepare a table for SQL

Choose fields, add useful indexes and read the returned values correctly.

A SQL query can use the table and columns you have registered.

Define and check a table with SQLUse the supported SQL interface; the PostgreSQL database login does not currently provide writes.
  1. Write CREATE TABLEChoose the fields, types and primary key.
  2. Run the definitionInspect the response before inserting data.
  3. Add a small sampleUse values that satisfy the declared types and rules.
  4. Read and inspect the tableVerify the stored fields before adding more queries or indexes.

Prepare the table

  1. Define the table's primary key and columns.
  2. Register the schema before writing rows.
  3. Add indexes for the filters your application actually uses.
  4. Use EXPLAIN to check whether a query uses an index or scans the table.

The example below uses its own shop.orders table; it is separate from the quickstart's quickstart.products table.

Example orders schema
namespace   = "shop"
table       = "orders"
primary_key = ["id"]

[[columns]]
name = "id"
ty   = "str"
required = true

[[columns]]
name = "customer"
ty   = "str"

[[columns]]
name = "amount_cents"
ty   = "i64"

[[columns]]
name = "status"
ty   = "str"

[[columns]]
name = "notes"
ty   = "str"

[[columns]]
name = "placed_ms"
ty   = "u64"

# Turns WHERE status = '...' into a sub-linear lookup.

[[indexes]]
name    = "by_status"
columns = ["status"]

Understand returned values

ValueWhat your application should do
Text, UUID or IP addressKeep the returned string.
DecimalKeep the exact decimal text; use a decimal library for calculations.
Large integerUse a client that preserves its precision. Do not coerce it to a JavaScript number.
BooleanRead it as true or false.
JSON or listRead the object or array, rather than treating it as prose.
Date or timestampInspect the returned column type and format before converting it.

Older clients that decode every JSON number as a floating-point value can round large integers. The newer SDK contract preserves numeric strings; check the SDK version you are using.

Temporal columns can be returned as formatted text. Calculations over those columns may return a different representation, so test the exact expression your application uses.

Choose the next task

© 2026 Silicoyn Technologies Pvt Ltd

On this page