Generate random data in PostgreSQL
When doing programming you often need to generate some random data to use in your tests, this is the same when you manage PostgreSQL databases.
I won’t explain here how to generate simple data like integer, as PostgreSQL already allows it as simple as :
I will share with you the functions I use, I wrote some of them and re-use others, no need to reinvent the wheels particulary when it womes fomr the excellent https://www.depesz.com/
First function the random date generator, when using dat you may need to be sure they will be in past or in future, and in a well defined window.
The get_random_date() function will allows you to define the window and if you need a date after or before now.
You will find all the functions in the Github repo https://github.com/rodo/articles/tree/main/postgresql-random-functions
Enjoy !