Sql
Find values within a range
The language tabs use earlier client interfaces. Check SDK versions and connection setup before running them.
Find orders whose amount is between two limits. This example stores prices as integer cents.
Before you run it: Use > and < when the endpoints must be excluded.
- Read order amountsUse the integer amounts in the sample table.
- Apply 1000 through 10000BETWEEN includes both endpoint values.
- Inspect matching ordersRows below or above the range are excluded.
Follow the example
- Load the orders from the linked setup.
- Set the lower and upper amounts.
- Run the query.
- Check values at both boundaries.
Run the request
First register and load the orders sample: shop.orders has id, customer_id, amount_cents and status. Use its three sample rows for the results shown here.
curl -X POST "https://$OC_HOST/v1/tenants/$OC_TENANT/sql" \
-H "Authorization: Bearer $OC_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"sql": "SELECT id, amount_cents FROM shop.orders WHERE amount_cents BETWEEN 1000 AND 10000 LIMIT 50"
}'Check the result
BETWEEN includes both endpoints: 1000 and 10000 match.
{
"kind": "select",
"rows": [
{ "id": "o_001", "amount_cents": 4990 },
{ "id": "o_003", "amount_cents": 1250 }
]
}Important limits and checks
- Off-by-one. BETWEEN is inclusive on both ends. If you mean exclusive, use
col > low AND col < high. - Keep the units consistent. This table uses integer cents, so 1000 means 10.00 in the chosen currency. Exact decimal fields are another option; avoid binary floating-point values when exact monetary comparisons matter.