Skip to content

Instantly share code, notes, and snippets.

@jdaarevalo
Created January 30, 2021 12:10
Show Gist options
  • Save jdaarevalo/3b85e2774fb2c4a72fec6bd7930dd44a to your computer and use it in GitHub Desktop.
Save jdaarevalo/3b85e2774fb2c4a72fec6bd7930dd44a to your computer and use it in GitHub Desktop.
third-section-fill_tables
CREATE EXTENSION pgcrypto;
--select gen_random_uuid ();
...
-- Filling of sales
INSERT INTO sale;
select gen_random_uuid ()
, round(CAST(float8 (random() * 10000) as numeric), 3)
, TO_TIMESTAMP(start_date, 'YYYY-MM-DD HH24:MI:SS') +
random()* (TO_TIMESTAMP(end_date, 'YYYY-MM-DD HH24:MI:SS')
- TO_TIMESTAMP(start_date, 'YYYY-MM-DD HH24:MI:SS'))
, floor(random() * (current_setting('my.number_of_products')::int) + 1)::int
, floor(random() * (current_setting('my.number_of_users')::int) + 1)::int
, floor(random() * (current_setting('my.number_of_stores')::int) + 1)::int
FROM GENERATE_SERIES(1, current_setting('my.number_of_sales')::int) as id
, current_setting('my.start_date') as start_date
, current_setting('my.end_date') as end_date;
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment