/
kotter
/
Homework_subd
Обзор
Документация
Войти
/
kotter
/
Homework_subd
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
4_task_subd/postgres/02_data.sql
40 строк
2 KB
Ксения Выдрина
Добавлено полностью четвертое задание
17 апр 2026, 20:37
17 апр 2026, 20:37
7fa0089
Код
Авторство
О чём код?
INSERT INTO customers (customer_id, full_name, region, registration_date) SELECT gs AS customer_id, 'Customer ' || gs AS full_name, (ARRAY['RU','EU','KZ','BY','UZ'])[(1 + floor(random() * 5))::int] AS region, DATE '2024-01-01' + ((random() * 420)::int) AS registration_date FROM generate_series(1, 300) AS gs; INSERT INTO products (product_id, product_name, category, price) SELECT gs AS product_id, 'Product ' || gs AS product_name, CASE WHEN gs BETWEEN 1 AND 25 THEN 'Smartphones' WHEN gs BETWEEN 26 AND 50 THEN 'Laptops' WHEN gs BETWEEN 51 AND 75 THEN 'Accessories' ELSE 'Audio' END AS category, ROUND((10 + random() * 1990)::numeric, 2) AS price FROM generate_series(1, 100) AS gs; INSERT INTO orders (order_id, customer_id, order_ts, status) SELECT gs AS order_id, (1 + floor(random() * 300))::int AS customer_id, TIMESTAMP '2025-01-01 00:00:00' + ((random() * 120)::int || ' days')::interval + ((random() * 23)::int || ' hours')::interval + ((random() * 59)::int || ' minutes')::interval AS order_ts, (ARRAY['created','paid','shipped','completed'])[(1 + floor(random() * 4))::int] AS status FROM generate_series(1, 1500) AS gs; INSERT INTO order_items (order_item_id, order_id, product_id, quantity, unit_price) SELECT gs AS order_item_id, (1 + floor(random() * 1500))::int AS order_id, (1 + floor(random() * 100))::int AS product_id, (1 + floor(random() * 4))::int AS quantity, ROUND((10 + random() * 1990)::numeric, 2) AS unit_price FROM generate_series(1, 7000) AS gs;