Quickstart

Create a table, load a few events, and query them with ScopeQL.

This tutorial uses event data as a compact example. ScopeDB does not require this schema, an event model, or a time column.

Open ScopeDB Console, then open Query. Run each ScopeQL block below in order. You do not need an API address or API key for this Console workflow.

1. Create an event table

Event data usually has a few fields you query often and a larger payload that changes over time. Start with typed columns for stable fields and an object column for the original event.

CREATE TABLE events (
    time timestamp,
    service string,
    name string,
    message string,
    var object
);

2. Insert sample events

Use VALUES to create a small input relation, then reshape each row before inserting it.

VALUES
    (
        NOW(),
        'checkout',
        'checkout_started',
        'User opened checkout',
        {'region': 'apac', 'plan': 'pro'}
    ),
    (
        NOW() - 'PT3s'::interval,
        'checkout',
        'payment_failed',
        'Credit card gateway timed out',
        {'region': 'apac', 'gateway': 'credit_card'}
    )
SELECT
    $0 AS time,
    $1::string AS service,
    $2::string AS name,
    $3::string AS message,
    $4::object AS var
INSERT INTO events;

3. Query recent events

ScopeQL is a pipeline. Start from a relation, filter it, then select the fields you want to return.

FROM events
WHERE time >= NOW() - 'PT15m'::interval
  AND service = 'checkout'
SELECT time, name, message, var['region']::string AS region
ORDER BY time DESC
LIMIT 10;

4. Aggregate events

Use GROUP BY ... AGGREGATE to summarize the same table.

FROM events
WHERE time >= NOW() - 'PT15m'::interval
GROUP BY service, name
AGGREGATE count() AS events
ORDER BY events DESC;

5. Next steps

Continue with: