Created
January 30, 2021 12:10
-
-
Save jdaarevalo/3b85e2774fb2c4a72fec6bd7930dd44a to your computer and use it in GitHub Desktop.
third-section-fill_tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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