fejkdata · Guides

Generate Swedish test customers into PostgreSQL

This guide fills a customers table with 100,000 Swedish people. A personnummer is Sweden's national id number. In each row it spells the birth date and the sex, passes its check digit, and comes from the tax agency Skatteverket's test series, so no real person has it. The postal code belongs to the town.

You need fejkdata installed and psql connected to a PostgreSQL database, here mydb.

1. Create the table

CREATE TABLE customers (
  id bigint PRIMARY KEY,
  first text NOT NULL,
  last text NOT NULL,
  sex text NOT NULL,
  birthdate date NOT NULL,
  personnummer text NOT NULL,
  email text NOT NULL,
  street text NOT NULL,
  postal_code text NOT NULL,
  locality text NOT NULL
);

2. Save the template

Save this as customers.json. Its format draws one person and one address, and each column reads those same draws. {seq()} counts the rows from 1 for id.

{
  "format": "{/sv_SE.person as p}{/sv_SE.address as a}",
  "id": { "format": "{seq()}", "datatype": "integer" },
  "first": "{p.first}",
  "last": "{p.last}",
  "sex": "{p.sex}",
  "birthdate": "{p.birthdate}",
  "personnummer": "{p.personnummer}",
  "email": "{slugify(p.first)}.{slugify(p.last)}@example.com",
  "street": "{a.street} {a.street-number}",
  "postal_code": "{a.postal-code}",
  "locality": "{a.locality}"
}

3. Look at two rows

With --seed and --today the same rows come out on every run, on any day: ages, and so birth dates and personnummer, count from the day you give.

fejkdata --seed 1 --today 2026-11-21 --format csv --repeat 2 < customers.json

This prints, with fejkdata v0.8.0:

birthdate,email,first,id,last,locality,personnummer,postal_code,sex,street
1994-02-15,karrar.rahimi@example.com,Karrar,1,Rahimi,Östersund,940215-2392,831 34,man,Sånghusvägen 9
2016-05-20,linn.stensson@example.com,Linn,2,Stensson,Växjö,160520-2389,352 42,kvinna,Arabygatan 69W

4. Load 100,000 rows with COPY

Under --format pgcopy fejkdata writes one COPY block that psql reads from its standard input. --table names the table, and -v ON_ERROR_STOP=1 makes psql stop at a missing table or column.

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

5. Keep the key on id

Rows are drawn independently, so values repeat: the 100,000 rows above hold 52,762 different personnummer and 80,258 different emails. Leave personnummer and email without UNIQUE, and let id be the key.

More: Load into a database, Swedish personnummer and Records.