# PartiQL: set up the sample tables

Every example in the [dialect series](https://www.kanject.com/docs/dynostudio-partiql/) queries one of three sample tables — `stage.Users`, `stage.Outbox`, `stage.Orders` — and the data is built so the queries the pages print return the rows the pages show. You don't need any of it to *read* the series (the in-page playgrounds run right where they are), but to type along in the studio you want these tables seeded first. Both paths take a couple of minutes: **import the ready-made files into DynoStudio** (no AWS account), or **stand up a free local DynamoDB** and load everything with one command.

**You'll learn**

- Create the three `stage.*` tables — all keyed `pk` (string) + `sk` (string), on-demand
- Load the 2,595-item sample, by **importing** into DynoStudio or **seeding** DynamoDB Local
- Know which indexes ship with the data and which ones the series has you create yourself
- Confirm the load with a single cheap query

> **What you're building:** Three small tables, one per teaching job: `stage.Users` (750 profiles — your first SELECTs, projections, GSI reads), `stage.Outbox` (645 delivery events — the Query/Scan divide and sort-key ranges), `stage.Orders` (1,200 orders — the multi-key GSI and `PROFILE TABLE`'s messy-data report). All three share the `pk`/`sk` string key shape.

## Get the files

**One download covers both paths:** the bundle below holds the three data files, the three table definitions, the local seed script, and the dataset README. Prefer single files? Each one is listed after it.

**Download**

- [Everything — partiql-stage.zip](/datasets/partiql-stage/partiql-stage.zip) — The whole dataset in one file (~140 KB). Extract it and you're ready for either path below.
- [stage.Users sample (DynamoDB-JSON)](/datasets/partiql-stage/stage-users.ddb.json) — 750 user profiles — Ada Okafor (User#9) included. Import into stage.Users.
- [stage.Outbox sample (DynamoDB-JSON)](/datasets/partiql-stage/stage-outbox.ddb.json) — 645 delivery events — exactly three of them pending. Import into stage.Outbox.
- [stage.Orders sample (DynamoDB-JSON)](/datasets/partiql-stage/stage-orders.ddb.json) — 1,200 orders carrying the byRegionStatus key attributes. Import into stage.Orders.
- [stage.Users table definition](/datasets/partiql-stage/schema-users.json) — Key schema pk/sk (strings), on-demand — including the ByOrg GSI. Used by the seed script and by aws dynamodb create-table.
- [stage.Outbox table definition](/datasets/partiql-stage/schema-outbox.json) — Key schema pk/sk (strings), on-demand.
- [stage.Orders table definition](/datasets/partiql-stage/schema-orders.json) — Key schema pk/sk (strings), on-demand — byRegionStatus is created later, in the studio.
- [Local seed script](/datasets/partiql-stage/seed-stage-tables.mjs) — A zero-dependency loader for DynamoDB Local — creates all three tables from the schemas and loads every item. Uses the aws CLI you already have.

## Path A — Import into DynoStudio

**1. Create the tables.** In DynoStudio, create each table with partition key `pk` (String) and sort key `sk` (String), billed on-demand — or run the statements in the query box. `CREATE TABLE` is a DynoStudio dialect surface (DynamoDB's own PartiQL has [no DDL](https://www.kanject.com/docs/dynostudio-partiql-ddl/)); the "Executes as" strip shows each `CreateTable` call before it runs:

```sql
CREATE TABLE "stage.Users" (
  PARTITION KEY pk STRING,
  SORT KEY sk STRING
) WITH BILLING = ON_DEMAND;

CREATE TABLE "stage.Outbox" (
  PARTITION KEY pk STRING,
  SORT KEY sk STRING
) WITH BILLING = ON_DEMAND;

CREATE TABLE "stage.Orders" (
  PARTITION KEY pk STRING,
  SORT KEY sk STRING
) WITH BILLING = ON_DEMAND;
```

**2. Add the `ByOrg` index** — the series' first GSI read uses it, and on this path it doesn't exist yet:

```sql
CREATE GLOBAL INDEX "ByOrg" ON "stage.Users"
  PARTITION KEY (OrgId)
  PROJECT ALL
```

**3. Import the data.** Open each table, choose **Import from CSV & JSON**, pick its `.ddb.json` file, and review the key-aware preview before it writes. Import order doesn't matter.

> **Tip:** Done here? Skip to [Confirm it worked](https://www.kanject.com/docs/dynostudio-partiql-setup/#confirm-it-worked) — then [First queries](https://www.kanject.com/docs/dynostudio-partiql-basics/) is the front door.

## Path B — Run it locally with DynamoDB Local

Prefer your own endpoint, offline and free? Stand up **DynamoDB Local** and let the seed script do everything: it creates all three tables from the shipped schemas (including `ByOrg`), then batch-writes every item, retrying anything DynamoDB leaves unprocessed — safe to re-run. You need the `aws` CLI and a way to run DynamoDB Local; Docker is easiest. From the extracted `partiql-stage/` folder:

```bash
# 1. run DynamoDB Local (Docker shown; any method works)
docker run -p 8000:8000 amazon/dynamodb-local

# 2. from the folder you downloaded: create all three tables and load
#    2,595 items (defaults to localhost:8000 — no AWS account needed)
node seed-stage-tables.mjs
```

When it finishes, **point DynoStudio at the same endpoint** (`http://localhost:8000`) and open the tables. One table only? `node seed-stage-tables.mjs --only stage.Orders`.

> **Seeding real AWS instead of local:** One flag drops the local override and uses your normal credentials and region: `node seed-stage-tables.mjs --endpoint '' --region eu-west-1`. That creates three **real, billed** tables in your account — DynamoDB Local is the free, offline default for a reason.

## The indexes: one ships, two are lessons

- **`ByOrg`** (on `stage.Users`) — ships with the setup above, so `FROM "stage.Users"."ByOrg"` works from your very first page.
- **`byEmail`** (on `stage.Users`) — deliberately *not* pre-created: building it is the [CREATE GLOBAL INDEX](https://www.kanject.com/docs/dynostudio-create-gsi/) lesson. The `email` attribute is already on every profile, so it backfills the moment you run the statement.
- **`byRegionStatus`** (on `stage.Orders`) — the **multi-key** GSI from [Targeted reads](https://www.kanject.com/docs/dynostudio-partiql-reads/). Its key attributes (`region`, `tenant`, `status`, `createdAt`) are on every seeded order; create it now if you want that example live when you reach it:

```sql
CREATE GLOBAL INDEX "byRegionStatus" ON "stage.Orders"
  PARTITION KEY (region, tenant)
  SORT KEY (status, createdAt)
  PROJECT ALL
```

## Confirm it worked

However you loaded it, open `stage.Users` and run one cheap keyed read:

```sql
SELECT Name, balance, address.city
FROM "stage.Users" WHERE pk = 'User#9'
```

One row: **Ada Okafor · 1,420.50 · Lagos**. That's the keyed read from the [First queries](https://www.kanject.com/docs/dynostudio-partiql-basics/) playground, so if it comes back you're fully set up. (Table-name error or empty result? The import/seed didn't land — re-run the path above.)

> **Your item counts will be smaller — that's expected:** The series' prose describes big production tables (~12,480 users, ~432,926 outbox events, ~48,000 orders); this sample is a faithful **2,595-item slice** that imports in seconds. Every *pinned answer* reproduces — Ada's row, the three pending events, the two open `eu`/`acme` orders — but raw counts in the cost strip will be smaller than the prose numbers. The lesson is always the *ratio* a Query saves over a Scan, not the absolute count.

**Recap**

- Three tables — `stage.Users`, `stage.Outbox`, `stage.Orders` — all keyed `pk` (string) + `sk` (string), on-demand.
- **Import path:** create the tables (UI or `CREATE TABLE`), add `ByOrg`, then **Import from CSV & JSON** per table.
- **Local path:** `docker run … amazon/dynamodb-local`, then `node seed-stage-tables.mjs`, then point DynoStudio at `http://localhost:8000`.
- `ByOrg` ships; `byEmail` and `byRegionStatus` are created in the studio — that's part of the course.
- A keyed read on `pk = 'User#9'` returns Ada Okafor — proof the data landed.

> **Tables up, data in — start the series:** Head to [First queries](https://www.kanject.com/docs/dynostudio-partiql-basics/): your first `SELECT`, projections and computed columns, and the "Executes as" habit that makes the whole dialect legible.

**AWS reference**

- [Run DynamoDB Local](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html) — AWS docs: run DynamoDB on your own machine — free, offline, nothing to provision.
- [Working with tables in DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithTables.Basics.html) — AWS docs: creating tables, key schema, and on-demand vs provisioned billing.

---
_Source: https://www.kanject.com/docs/dynostudio-partiql-setup/ · Kanject Docs_
