Hacker News new | ask | show | jobs
by Gustek 2520 days ago
> Generating and inserting fake data

Sounds very promising just to be very quickly downgraded to

> something simple and quick

In this case that is only how to insert a bunch of rows that have only numbers and timestamps as these are types that `generate_series` supports.

Maybe someone will actually find it useful, so not saying that a tip is completely useless but personally I think it will be very rare for it to be actually fit for purpose. A huge majority of the time when I need to generate fake data there are other data types involved and usually, there are some constraints between them as well.

Other tips sound very nice and will keep them in my notes.

2 comments

The value from generate_series is not used for anything, it is only used to generate the listed number of rows. The actual value in the examples is only provided by random(). You can create random strings, or other data types, to use with scalar selects.

I had never thought of using generate_series for inserting random data, but like you said for some tables it doesn't make sense to use purely random values.

For text you can just concatenate a number on to whatever fixed text you want which is usually good enough for my testing. Also from text you can construct other types so a combination of these should cover most needs.