Generating Mock Data for Postgres

October 29th, 2018


I created Faker.sql, my first Postgres extension for generating mock data.

What’s the point of it?

When generating mock data for product screenshots or demo pages, you can’t just insert random characters. You want active user charts that go “up and to the right” and user names that aren’t just random alphanumeric string, but are believable names with corresponding email addresses. “Jane Doe” working at “Widgets Co” will probably have the email address “jane.doe@widgets.co”.

With some testing, this isn’t actually faster than just doing this in Python and the syntax is definitely much worse, so I probably won’t continue.

insert into test select generate_series(1, 1000000); -- 2.947 seconds
import psycopg2

i = 0
with open('/tmp/.test.csv', 'w') as f:
    while i < 1000000:
        f.write(str(i) + '\n')
        i += 1

conn = psycopg.connect('DSN')
curs = conn.cursor()
curs.execute("copy test from '/tmp/test.csv';")

# 1.211 seconds