fejkdata · Guides

Fill a test database with a million rows

One template and one command write a million rows as CSV, SQL INSERTs or PostgreSQL COPY. fejkdata's CLI writes up to 1,048,576 rows a run, and {seq()} keeps a UNIQUE column unique.

You need fejkdata installed. The loads below use psql on a PostgreSQL database, here mydb, with this table:

CREATE TABLE users (
  id bigint PRIMARY KEY,
  name text NOT NULL,
  email text NOT NULL UNIQUE
);

1. Save the template

Save this as users.json. {seq()} counts the rows from 1 for id, and {seq(email)} is a counter of its own for the email.

{
  "format": "{/en_US.person as p}",
  "id": { "format": "{seq()}", "datatype": "integer" },
  "name": "{p.first} {p.last}",
  "email": "{/en_US.username}.{seq(email)}@example.com"
}

2. Look at three rows

fejkdata --seed 1 --today 2026-11-21 --format csv --repeat 3 < users.json

This prints, with fejkdata v0.8.0:

email,id,name
derpina14.1@example.com,1,Yusuf Mabe
waooooh42.2@example.com,2,Fernanda Gardner
neon_potato123.3@example.com,3,Alexis Culpepper

3. Write a million rows

Pick the form your database loads. Each line writes the same rows, in the same order.

CSV, with the columns in name order, so the load lists them in that order:

fejkdata --seed 1 --today 2026-11-21 --format csv --repeat 1000000 < users.json > users.csv
psql -c '\copy users (email, id, name) FROM users.csv WITH (FORMAT csv, HEADER)' mydb

SQL INSERTs, a thousand rows to a statement. --table names the table:

fejkdata --seed 1 --today 2026-11-21 --format sql --table users --repeat 1000000 < users.json > users.sql
psql -v ON_ERROR_STOP=1 -f users.sql mydb

PostgreSQL COPY, piped straight into psql:

fejkdata --seed 1 --today 2026-11-21 --format pgcopy --table users --repeat 1000000 < users.json | psql -v ON_ERROR_STOP=1 mydb

fejkdata's README measured a million rows from a file into a table of id bigint primary key, name text on PostgreSQL 17 through psql: 1.4 s from pgcopy and 6.9 s from sql. Generating either file took about 1.3 s.

4. Keep the unique column unique

A random draw can repeat in a million rows, so a UNIQUE column needs a counter. The email ends in .{seq(email)}@example.com: the count is different on every row, so no two emails match, whatever is drawn before the dot. seq(email) counts the email column from 1.

More: Load into a database and Records.