Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joebartels/aaf35fd182a454610c589b3d996051c7 to your computer and use it in GitHub Desktop.
Save joebartels/aaf35fd182a454610c589b3d996051c7 to your computer and use it in GitHub Desktop.
using generate_series to create bunch of random dates throughout "a year"
with days as (
select *
from generate_series(
'1988-01-01T00:00:00'::timestamptz,
'2019-01-01T00:00:00'::timestamptz - '1 day'::interval,
'1 day'::interval
) as date
)
-- uncomment to insert into the table
-- insert into cycling_entry (date, km_cycled)
select date + ('1 day'::interval * int_between(-7, 7))
+ ('1 hour'::interval * int_between(0, 24))
+ ('1 minute'::interval * int_between(0, 60)) as date,
int_between(0, 100) as km_cycled
from days;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment