Repository navigation
Expand file tree
/
Copy patholist_copy.sql
More file actions
144 lines (134 loc) · 3.53 KB
/
Copy patholist_copy.sql
File metadata and controls
144 lines (134 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
-- PostgreSQL Оlist Copy
--
-- Database: olist_db
-- ------------------------------------------------------
-- @param datadir = /path_to/olist_dataset
-- ===============================================
-- 1. Delete data inside tables
-- ===============================================
TRUNCATE TABLE
olist.order_items,
olist.order_payments,
olist.order_reviews,
olist.geolocation,
olist.product_category_name_translation,
olist.orders,
olist.products,
olist.sellers,
olist.customers
RESTART IDENTITY CASCADE;
-- ===============================================
-- 2.1. Customers
-- ===============================================
COPY olist.customers (
customer_id,
customer_unique_id,
customer_zip_code_prefix,
customer_city,
customer_state
)
FROM '${datadir}/olist_customers_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.2. Sellers
-- ===============================================
COPY olist.sellers (
seller_id,
seller_zip_code_prefix,
seller_city,
seller_state
)
FROM '${datadir}/olist_sellers_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.3. Category name translation
-- ===============================================
COPY olist.product_category_name_translation (
product_category_name,
product_category_name_english
)
FROM '${datadir}/product_category_name_translation.csv'
CSV HEADER;
-- ===============================================
-- 2.4. Products
-- ===============================================
COPY olist.products (
product_id,
product_category_name,
product_name_lenght,
product_description_lenght,
product_photos_qty,
product_weight_g,
product_length_cm,
product_height_cm,
product_width_cm
)
FROM '${datadir}/olist_products_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.5. Orders
-- ===============================================
COPY olist.orders (
order_id,
customer_id,
order_status,
order_purchase_timestamp,
order_approved_at,
order_delivered_carrier_date,
order_delivered_customer_date,
order_estimated_delivery_date
)
FROM '${datadir}/olist_orders_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.6. Order payments
-- ===============================================
COPY olist.order_payments (
order_id,
payment_sequential,
payment_type,
payment_installments,
payment_value
)
FROM '${datadir}/olist_order_payments_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.7. Order items
-- ===============================================
COPY olist.order_items (
order_id,
order_item_id,
product_id,
seller_id,
shipping_limit_date,
price,
freight_value
)
FROM '${datadir}/olist_order_items_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.8. Order reviews
-- ===============================================
COPY olist.order_reviews (
review_id,
order_id,
review_score,
review_comment_title,
review_comment_message,
review_creation_date,
review_answer_timestamp
)
FROM '${datadir}/olist_order_reviews_dataset.csv'
CSV HEADER;
-- ===============================================
-- 2.9. Geolocation
-- ===============================================
COPY olist.geolocation (
geolocation_zip_code_prefix,
geolocation_lat,
geolocation_lng,
geolocation_city,
geolocation_state
)
FROM '${datadir}/olist_geolocation_dataset.csv'
CSV HEADER;