| | 39 | |
| | 40 | RETURNING order_id |
| | 41 | ) |
| | 42 | INSERT INTO project.order_products |
| | 43 | ( |
| | 44 | order_id, |
| | 45 | product_id, |
| | 46 | price_at_purchase, |
| | 47 | quantity |
| | 48 | ) |
| | 49 | SELECT |
| | 50 | no.order_id, |
| | 51 | p.product_id, |
| | 52 | p.price, |
| | 53 | 1 + floor(random() * 4)::bigint |
| | 54 | FROM new_orders no |
| | 55 | CROSS JOIN LATERAL ( |
| | 56 | SELECT |
| | 57 | product_id, |
| | 58 | price |
| | 59 | FROM project.products |
| | 60 | ORDER BY random() |
| | 61 | LIMIT 3 |
| | 62 | ) p; |
| | 63 | }}} |
| | 64 | |
| | 65 | {{{ |
| | 66 | WITH new_orders AS ( |
| | 67 | INSERT INTO project.orders |
| | 68 | ( |
| | 69 | user_id, |
| | 70 | payment_method, |
| | 71 | purchase_date, |
| | 72 | points_earned, |
| | 73 | points_used, |
| | 74 | status |
| | 75 | ) |
| | 76 | SELECT |
| | 77 | (ARRAY[1,2,3,5,6,7,8,10,11,12,13,14]) |
| | 78 | [1 + floor(random() * 12)::int], |
| | 79 | |
| | 80 | (ARRAY[ |
| | 81 | 'CARD'::project.payment_method_type, |
| | 82 | 'PAYPAL'::project.payment_method_type, |
| | 83 | 'CASH'::project.payment_method_type |
| | 84 | ]) |
| | 85 | [1 + floor(random() * 3)::int], |
| | 86 | |
| | 87 | CURRENT_DATE |
| | 88 | - 366 |
| | 89 | - floor(random() * 730)::int, |
| | 90 | |
| | 91 | floor(random() * 100)::bigint, |
| | 92 | |
| | 93 | NULL, |
| | 94 | |
| | 95 | 'CANCELLED'::project.order_status_type |
| | 96 | |
| | 97 | FROM generate_series(1, 20000) |