Reputation: 225
I have some tables in Postgres that I want to populate with dummy data. Is there a tool/utility that can help with this, that?
Upvotes: 0
Views: 1686
Reputation: 1699
Not exactly what you mentioned but here you can find a python program that (creates and/or) auto-populate tables with fake data. For anyone who is interested, check it out here if you want.
Upvotes: 1
Reputation: 142
You could try to read up generate_series() in postgresql, this function could be used to provide a table with dummy data.
insert into testscheme.testtable (id, name)
select generate_series, 'name1' from generate_series(1,250)
This will provide 250 rows in testtable. You can build further on this. For example replace 1,250 with the primary key contraint. For example with
nextval('testtable_pk'::regclass)
And if you would like the foreign key respected try to use a subselect: postgresql order by random(), select rows in random order:
select MAX(names) from testscheme.names ORDER BY random()
If you wrap this all in a function you can make a script to fill stuff :) Hope I could help.
Here is the documentation of generate_series() https://www.postgresql.org/docs/12/functions-srf.html
Upvotes: 1