-
Notifications
You must be signed in to change notification settings - Fork 15
/
001-import-2023-data.sql
1820 lines (1665 loc) Β· 144 KB
/
001-import-2023-data.sql
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- Insert 2023 data
--
INSERT INTO "public"."weekly_earnings" ("occupation", "slug", "parent", "total_number_workers", "median_weekly_earnings", "men_number_workers", "men_median_weekly_earnings", "women_number_workers", "women_median_weekly_earnings", "year") VALUES
('Sawing machine setters, operators, and tenders, wood', 'sawing-machine-setters-operators-and-tenders-wood', 'production-occupations', '31', '-', '30', '-', '1', '-', '2011'),
('Woodworking machine setters, operators, and tenders, except sawing', 'woodworking-machine-setters-operators-and-tenders-except-sawing', 'production-occupations', '17', '-', '15', '-', '2', '-', '2011'),
('Woodworkers, all other', 'woodworkers-all-other', 'production-occupations', '10', '-', '8', '-', '2', '-', '2011'),
('Power plant operators, distributors, and dispatchers', 'power-plant-operators-distributors-and-dispatchers', 'production-occupations', '53', '1,091', '52', '1,085', '1', '-', '2011'),
('Stationary engineers and boiler operators', 'stationary-engineers-and-boiler-operators', 'production-occupations', '93', '855', '92', '851', '1', '-', '2011'),
('Water and wastewater treatment plant and system operators', 'water-and-wastewater-treatment-plant-and-system-operators', 'production-occupations', '75', '780', '70', '788', '5', '-', '2011'),
('Miscellaneous plant and system operators', 'miscellaneous-plant-and-system-operators', 'production-occupations', '37', '-', '34', '-', '3', '-', '2011'),
('Chemical processing machine setters, operators, and tenders', 'chemical-processing-machine-setters-operators-and-tenders', 'production-occupations', '66', '853', '52', '947', '14', '-', '2011'),
('Crushing, grinding, polishing, mixing, and blending workers', 'crushing-grinding-polishing-mixing-and-blending-workers', 'production-occupations', '94', '659', '82', '702', '12', '-', '2011'),
('Cutting workers', 'cutting-workers', 'production-occupations', '69', '518', '55', '540', '13', '-', '2011'),
('Extruding, forming, pressing, and compacting machine setters, operators, and tenders', 'extruding-forming-pressing-and-compacting-machine-setters-operators-and-tenders', 'production-occupations', '31', '-', '28', '-', '3', '-', '2011'),
('Furnace, kiln, oven, drier, and kettle operators and tenders', 'furnace-kiln-oven-drier-and-kettle-operators-and-tenders', 'production-occupations', '11', '-', '11', '-', '0', '-', '2011'),
('Inspectors, testers, sorters, samplers, and weighers', 'inspectors-testers-sorters-samplers-and-weighers', 'production-occupations', '608', '675', '396', '792', '212', '541', '2011'),
('Jewelers and precious stone and metal workers', 'jewelers-and-precious-stone-and-metal-workers', 'production-occupations', '14', '-', '7', '-', '7', '-', '2011'),
('Medical, dental, and ophthalmic laboratory technicians', 'medical-dental-and-ophthalmic-laboratory-technicians', 'production-occupations', '68', '612', '34', '-', '34', '-', '2011'),
('Packaging and filling machine operators and tenders', 'packaging-and-filling-machine-operators-and-tenders', 'production-occupations', '259', '455', '120', '505', '139', '421', '2011'),
('Painting workers', 'painting-workers', 'production-occupations', '111', '602', '99', '608', '12', '-', '2011'),
('Photographic process workers and processing machine operators', 'photographic-process-workers-and-processing-machine-operators', 'production-occupations', '24', '-', '10', '-', '13', '-', '2011'),
('Semiconductor processors', 'semiconductor-processors', 'production-occupations', '4', '-', '3', '-', '1', '-', '2011'),
('Adhesive bonding machine operators and tenders', 'adhesive-bonding-machine-operators-and-tenders', 'production-occupations', '10', '-', '4', '-', '6', '-', '2011'),
('Cleaning, washing, and metal pickling equipment operators and tenders', 'cleaning-washing-and-metal-pickling-equipment-operators-and-tenders', 'production-occupations', '13', '-', '9', '-', '3', '-', '2011'),
('Cooling and freezing equipment operators and tenders', 'cooling-and-freezing-equipment-operators-and-tenders', 'production-occupations', '3', '-', '3', '-', '0', '-', '2011'),
('Etchers and engravers', 'etchers-and-engravers', 'production-occupations', '7', '-', '4', '-', '2', '-', '2011'),
('Molders, shapers, and casters, except metal and plastic', 'molders-shapers-and-casters-except-metal-and-plastic', 'production-occupations', '21', '-', '15', '-', '6', '-', '2011'),
('Paper goods machine setters, operators, and tenders', 'paper-goods-machine-setters-operators-and-tenders', 'production-occupations', '31', '-', '23', '-', '8', '-', '2011'),
('Tire builders', 'tire-builders', 'production-occupations', '17', '-', '16', '-', '1', '-', '2011'),
('Helpers--production workers', 'helpers-production-workers', 'production-occupations', '45', '-', '40', '-', '6', '-', '2011'),
('Production workers, all other', 'production-workers-all-other', 'production-occupations', '652', '579', '502', '612', '151', '483', '2011'),
('Transportation and material moving occupations', 'transportation-and-material-moving-occupations', 'production-transportation-and-material-moving-occupations', '6,275', '614', '5,489', '634', '786', '490', '2011'),
('Supervisors of transportation and material moving workers', 'supervisors-of-transportation-and-material-moving-workers', 'transportation-and-material-moving-occupations', '208', '761', '170', '773', '38', '-', '2011'),
('Aircraft pilots and flight engineers', 'aircraft-pilots-and-flight-engineers', 'transportation-and-material-moving-occupations', '93', '1,461', '89', '1,466', '4', '-', '2011'),
('Air traffic controllers and airfield operations specialists', 'air-traffic-controllers-and-airfield-operations-specialists', 'transportation-and-material-moving-occupations', '40', '-', '35', '-', '5', '-', '2011'),
('Flight attendants', 'flight-attendants', 'transportation-and-material-moving-occupations', '52', '791', '14', '-', '38', '-', '2011'),
('Ambulance drivers and attendants, except emergency medical technicians', 'ambulance-drivers-and-attendants-except-emergency-medical-technicians', 'transportation-and-material-moving-occupations', '9', '-', '9', '-', '0', '-', '2011'),
('Bus drivers', 'bus-drivers', 'transportation-and-material-moving-occupations', '310', '608', '188', '645', '122', '579', '2011'),
('Driver/sales workers and truck drivers', 'driver-sales-workers-and-truck-drivers', 'transportation-and-material-moving-occupations', '2,439', '705', '2,337', '712', '102', '511', '2011'),
('Motor vehicle operators, all other', 'motor-vehicle-operators-all-other', 'transportation-and-material-moving-occupations', '28', '-', '26', '-', '1', '-', '2011'),
('Locomotive engineers and operators', 'locomotive-engineers-and-operators', 'transportation-and-material-moving-occupations', '43', '-', '42', '-', '2', '-', '2011'),
('Railroad brake, signal, and switch operators', 'railroad-brake-signal-and-switch-operators', 'transportation-and-material-moving-occupations', '6', '-', '6', '-', '0', '-', '2011'),
('Railroad conductors and yardmasters', 'railroad-conductors-and-yardmasters', 'transportation-and-material-moving-occupations', '48', '-', '45', '-', '3', '-', '2011'),
('Subway, streetcar, and other rail transportation workers', 'subway-streetcar-and-other-rail-transportation-workers', 'transportation-and-material-moving-occupations', '14', '-', '12', '-', '2', '-', '2011'),
('Sailors and marine oilers', 'sailors-and-marine-oilers', 'transportation-and-material-moving-occupations', '23', '-', '23', '-', '0', '-', '2011'),
('Ship and boat captains and operators', 'ship-and-boat-captains-and-operators', 'transportation-and-material-moving-occupations', '35', '-', '35', '-', '0', '-', '2011'),
('Ship engineers', 'ship-engineers', 'transportation-and-material-moving-occupations', '6', '-', '6', '-', '0', '-', '2011'),
('Bridge and lock tenders', 'bridge-and-lock-tenders', 'transportation-and-material-moving-occupations', '7', '-', '7', '-', '0', '-', '2011'),
('Parking lot attendants', 'parking-lot-attendants', 'transportation-and-material-moving-occupations', '46', '-', '40', '-', '5', '-', '2011'),
('Automotive and watercraft service attendants', 'automotive-and-watercraft-service-attendants', 'transportation-and-material-moving-occupations', '42', '-', '40', '-', '2', '-', '2011'),
('Transportation inspectors', 'transportation-inspectors', 'transportation-and-material-moving-occupations', '32', '-', '28', '-', '5', '-', '2011'),
('Transportation attendants, except flight attendants', 'transportation-attendants-except-flight-attendants', 'transportation-and-material-moving-occupations', '13', '-', '5', '-', '8', '-', '2011'),
('Other transportation workers', 'other-transportation-workers', 'transportation-and-material-moving-occupations', '15', '-', '14', '-', '1', '-', '2011'),
('Conveyor operators and tenders', 'conveyor-operators-and-tenders', 'transportation-and-material-moving-occupations', '5', '-', '2', '-', '3', '-', '2011'),
('Crane and tower operators', 'crane-and-tower-operators', 'transportation-and-material-moving-occupations', '63', '739', '62', '736', '1', '-', '2011'),
('Dredge, excavating, and loading machine operators', 'dredge-excavating-and-loading-machine-operators', 'transportation-and-material-moving-occupations', '37', '-', '37', '-', '0', '-', '2011'),
('Hoist and winch operators', 'hoist-and-winch-operators', 'transportation-and-material-moving-occupations', '5', '-', '3', '-', '2', '-', '2011'),
('Industrial truck and tractor operators', 'industrial-truck-and-tractor-operators', 'transportation-and-material-moving-occupations', '491', '562', '456', '556', '35', '-', '2011'),
('Cleaners of vehicles and equipment', 'cleaners-of-vehicles-and-equipment', 'transportation-and-material-moving-occupations', '230', '465', '206', '458', '25', '-', '2011'),
('Laborers and freight, stock, and material movers, hand', 'laborers-and-freight-stock-and-material-movers-hand', 'transportation-and-material-moving-occupations', '1,260', '509', '1,085', '520', '175', '416', '2011'),
('Machine feeders and offbearers', 'machine-feeders-and-offbearers', 'transportation-and-material-moving-occupations', '32', '-', '27', '-', '5', '-', '2011'),
('Packers and packagers, hand', 'packers-and-packagers-hand', 'transportation-and-material-moving-occupations', '300', '397', '135', '396', '165', '397', '2011'),
('Pumping station operators', 'pumping-station-operators', 'transportation-and-material-moving-occupations', '26', '-', '26', '-', '0', '-', '2011'),
('Refuse and recyclable material collectors', 'refuse-and-recyclable-material-collectors', 'transportation-and-material-moving-occupations', '58', '541', '56', '580', '3', '-', '2011'),
('Mine shuttle car operators', 'mine-shuttle-car-operators', 'transportation-and-material-moving-occupations', '1', '-', '0', '-', '1', '-', '2011'),
('Tank car, truck, and ship loaders', 'tank-car-truck-and-ship-loaders', 'transportation-and-material-moving-occupations', '3', '-', '2', '-', '0', '-', '2011'),
('Material moving workers, all other', 'material-moving-workers-all-other', 'transportation-and-material-moving-occupations', '45', '-', '42', '-', '3', '-', '2011');
--
-- Cast wages to int
--
-- Set not enough data cols to 0
UPDATE weekly_earnings SET median_weekly_earnings = NULL WHERE median_weekly_earnings = '-';
-- 2024-03-09 18:40:53.2210
UPDATE weekly_earnings SET men_median_weekly_earnings = NULL WHERE men_median_weekly_earnings = '-';
-- 2024-03-09 18:40:53.2370
UPDATE weekly_earnings SET women_median_weekly_earnings = NULL WHERE women_median_weekly_earnings = '-';
-- 2024-03-09 18:40:53.2540
-- Remove commas from number strings
UPDATE weekly_earnings SET median_weekly_earnings = REPLACE(median_weekly_earnings, ',', '')::numeric;
-- 2024-03-09 18:40:53.2700
UPDATE weekly_earnings SET men_median_weekly_earnings = REPLACE(men_median_weekly_earnings, ',', '')::numeric;
-- 2024-03-09 18:40:53.2860
UPDATE weekly_earnings SET women_median_weekly_earnings = REPLACE(women_median_weekly_earnings, ',', '')::numeric;
-- 2024-03-09 18:40:53.3080
-- Cast wages to int
ALTER TABLE weekly_earnings ALTER COLUMN median_weekly_earnings TYPE int USING median_weekly_earnings::integer;
-- 2024-03-09 18:40:53.3210
ALTER TABLE weekly_earnings ALTER COLUMN men_median_weekly_earnings TYPE int USING men_median_weekly_earnings::integer;
-- 2024-03-09 18:40:53.3360
ALTER TABLE weekly_earnings ALTER COLUMN women_median_weekly_earnings TYPE int USING women_median_weekly_earnings::integer;
-- 2024-03-09 18:40:53.3670
--
-- Populate occupations table
--
INSERT INTO occupations (name, slug, parent_slug_denorm)
SELECT
occupation,
slug,
parent
FROM
weekly_earnings ON CONFLICT DO NOTHING;
-- 2024-03-09 18:40:53.3750
-- Set parent_id
UPDATE
occupations o1
SET
parent_id = o2.id
FROM
occupations o2
WHERE
o2.slug = o1.parent_slug_denorm;
-- 2024-03-09 18:40:53.3790
--
-- Populate gaps table
--
-- Move over weekly_earnings data
INSERT INTO wage_gaps (occupation_id, all_median_weekly_earnings, men_median_weekly_earnings, women_median_weekly_earnings, year)
SELECT
occupations.id,
median_weekly_earnings,
men_median_weekly_earnings,
women_median_weekly_earnings,
year
FROM
weekly_earnings
INNER JOIN occupations ON weekly_earnings.slug = occupations.slug;
-- 2024-03-09 18:40:53.3930
-- Calculate cents_to_dollar
UPDATE
wage_gaps
SET
cents_to_dollar = ROUND((women_median_weekly_earnings::numeric * 100) / men_median_weekly_earnings::numeric)
WHERE
men_median_weekly_earnings IS NOT NULL
AND women_median_weekly_earnings IS NOT NULL;
-- 2024-03-09 18:41:43.8070
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'occupations'
AND p.relkind = 'v';
-- 2024-03-09 18:41:43.8270
SELECT * FROM "public"."occupations" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:41:43.8270
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='occupations';
-- 2024-03-09 18:41:45.8940
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps'
AND p.relkind = 'v';
-- 2024-03-09 18:41:45.9180
SELECT * FROM "public"."wage_gaps" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:41:45.9180
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='wage_gaps';
-- 2024-03-09 18:41:48.3010
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'weekly_earnings'
AND p.relkind = 'v';
-- 2024-03-09 18:41:48.3220
SELECT * FROM "public"."weekly_earnings" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:41:48.3230
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='weekly_earnings';
-- 2024-03-09 18:57:50.5570
DROP VIEW IF EXISTS "wage_gaps_view";
-- 2024-03-09 18:57:50.5780
DROP TABLE IF EXISTS "wage_gaps";
-- 2024-03-09 18:57:50.5960
DROP TABLE IF EXISTS "occupations";
-- 2024-03-09 18:57:50.6070
DROP TABLE IF EXISTS "weekly_earnings";
-- 2024-03-09 18:57:50.6240
CREATE TABLE "occupations" (
"id" SERIAL PRIMARY KEY,
"slug" varchar,
"name" varchar,
"parent_id" int,
"parent_slug_denorm" varchar
);
-- 2024-03-09 18:57:50.6420
CREATE TABLE "wage_gaps" (
"id" SERIAL PRIMARY KEY,
"occupation_id" int,
"year" int,
"all_median_weekly_earnings" int,
"men_median_weekly_earnings" int,
"women_median_weekly_earnings" int,
"cents_to_dollar" int
);
-- 2024-03-09 18:57:50.6510
CREATE TABLE "weekly_earnings" (
"occupation" varchar,
"slug" varchar,
"parent" varchar,
"total_number_workers" varchar,
"median_weekly_earnings" varchar,
"men_number_workers" varchar,
"men_median_weekly_earnings" varchar,
"women_number_workers" varchar,
"women_median_weekly_earnings" varchar,
"year" int
);
-- 2024-03-09 18:57:50.6680
ALTER TABLE "occupations"
ADD FOREIGN KEY ("parent_id") REFERENCES "occupations" ("id");
-- 2024-03-09 18:57:50.6840
CREATE UNIQUE INDEX occupation_slugs_unique ON occupations (slug);
-- 2024-03-09 18:57:50.7020
ALTER TABLE "wage_gaps"
ADD FOREIGN KEY ("occupation_id") REFERENCES "occupations" ("id");
-- 2024-03-09 18:57:50.7200
CREATE VIEW wage_gaps_view AS
SELECT
o1.name,
o1.slug,
o2.name AS parent_name,
wg.cents_to_dollar,
wg.year
FROM
occupations o1
INNER JOIN occupations o2 ON o1.parent_id = o2.id
INNER JOIN wage_gaps wg ON wg.occupation_id = o1.id
WHERE
cents_to_dollar IS NOT NULL
ORDER BY
cents_to_dollar DESC;
-- 2024-03-09 18:57:53.3490
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'occupations'
AND p.relkind = 'v';
-- 2024-03-09 18:57:53.3590
SELECT * FROM "public"."occupations" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:57:53.3590
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='occupations';
-- 2024-03-09 18:57:53.3590
SELECT COUNT(*) as count FROM "public"."occupations";
-- 2024-03-09 18:57:53.9720
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps'
AND p.relkind = 'v';
-- 2024-03-09 18:57:53.9880
SELECT * FROM "public"."wage_gaps" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:57:53.9890
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='wage_gaps';
-- 2024-03-09 18:57:53.9890
SELECT COUNT(*) as count FROM "public"."wage_gaps";
-- 2024-03-09 18:59:03.9240
INSERT INTO "public"."weekly_earnings" ("total_number_workers", "parent", "occupation", "median_weekly_earnings", "men_number_workers", "slug", "women_number_workers", "women_median_weekly_earnings", "men_median_weekly_earnings", "year") VALUES
('120,907', '', 'Total, full-time wage and salary workers', 1,117, '66,700', 'total-full-time-wage-and-salary-workers', '54,207', 1,005, 1,202, 2,023);
-- 2024-03-09 18:59:26.1200
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'weekly_earnings'
AND p.relkind = 'v';
-- 2024-03-09 18:59:26.1370
SELECT * FROM "public"."weekly_earnings" LIMIT 300 OFFSET 0;
-- 2024-03-09 18:59:26.1380
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='weekly_earnings';
-- 2024-03-09 18:59:26.1380
SELECT COUNT(*) as count FROM "public"."weekly_earnings";
-- 2024-03-09 19:01:28.2710
DROP VIEW IF EXISTS "wage_gaps_view";
-- 2024-03-09 19:01:28.2890
DROP TABLE IF EXISTS "wage_gaps";
-- 2024-03-09 19:01:28.3050
DROP TABLE IF EXISTS "occupations";
-- 2024-03-09 19:01:28.3180
DROP TABLE IF EXISTS "weekly_earnings";
-- 2024-03-09 19:01:28.3340
CREATE TABLE "occupations" (
"id" SERIAL PRIMARY KEY,
"slug" varchar,
"name" varchar,
"parent_id" int,
"parent_slug_denorm" varchar
);
-- 2024-03-09 19:01:28.3440
CREATE TABLE "wage_gaps" (
"id" SERIAL PRIMARY KEY,
"occupation_id" int,
"year" int,
"all_median_weekly_earnings" int,
"men_median_weekly_earnings" int,
"women_median_weekly_earnings" int,
"cents_to_dollar" int
);
-- 2024-03-09 19:01:28.3570
CREATE TABLE "weekly_earnings" (
"occupation" varchar,
"slug" varchar,
"parent" varchar,
"total_number_workers" varchar,
"median_weekly_earnings" varchar,
"men_number_workers" varchar,
"men_median_weekly_earnings" varchar,
"women_number_workers" varchar,
"women_median_weekly_earnings" varchar,
"year" int
);
-- 2024-03-09 19:01:28.3680
ALTER TABLE "occupations"
ADD FOREIGN KEY ("parent_id") REFERENCES "occupations" ("id");
-- 2024-03-09 19:01:28.3800
CREATE UNIQUE INDEX occupation_slugs_unique ON occupations (slug);
-- 2024-03-09 19:01:28.3970
ALTER TABLE "wage_gaps"
ADD FOREIGN KEY ("occupation_id") REFERENCES "occupations" ("id");
-- 2024-03-09 19:01:28.4060
CREATE VIEW wage_gaps_view AS
SELECT
o1.name,
o1.slug,
o2.name AS parent_name,
wg.cents_to_dollar,
wg.year
FROM
occupations o1
INNER JOIN occupations o2 ON o1.parent_id = o2.id
INNER JOIN wage_gaps wg ON wg.occupation_id = o1.id
WHERE
cents_to_dollar IS NOT NULL
ORDER BY
cents_to_dollar DESC;
-- 2024-03-09 19:01:29.4190
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'weekly_earnings'
AND p.relkind = 'v';
-- 2024-03-09 19:02:34.9030
INSERT INTO "public"."weekly_earnings" ("women_number_workers", "parent", "men_number_workers", "median_weekly_earnings", "men_median_weekly_earnings", "total_number_workers", "year", "women_median_weekly_earnings", "occupation", "slug") VALUES
('54,207', '', '66,700', '1,117', '1,202', '120,907', 2,023, '1,005', 'Total, full-time wage and salary workers', 'total-full-time-wage-and-salary-workers');
-- 2024-03-09 19:04:09.0690
INSERT INTO "public"."weekly_earnings" ("occupation", "women_number_workers", "women_median_weekly_earnings", "total_number_workers", "median_weekly_earnings", "year", "men_number_workers", "parent", "men_median_weekly_earnings", "slug") VALUES
('Total, full-time wage and salary workers', '54,207', '1,005', '120,907', '1,117', 2,023, '66,700', '', '1,202', 'total-full-time-wage-and-salary-workers');
-- 2024-03-09 19:04:54.7260
DROP VIEW IF EXISTS "wage_gaps_view";
-- 2024-03-09 19:04:54.7450
DROP TABLE IF EXISTS "wage_gaps";
-- 2024-03-09 19:04:54.7640
DROP TABLE IF EXISTS "occupations";
-- 2024-03-09 19:04:54.7780
DROP TABLE IF EXISTS "weekly_earnings";
-- 2024-03-09 19:04:54.7940
CREATE TABLE "occupations" (
"id" SERIAL PRIMARY KEY,
"slug" varchar,
"name" varchar,
"parent_id" int,
"parent_slug_denorm" varchar
);
-- 2024-03-09 19:04:54.8060
CREATE TABLE "wage_gaps" (
"id" SERIAL PRIMARY KEY,
"occupation_id" int,
"year" int,
"all_median_weekly_earnings" int,
"men_median_weekly_earnings" int,
"women_median_weekly_earnings" int,
"cents_to_dollar" int
);
-- 2024-03-09 19:04:54.8180
CREATE TABLE "weekly_earnings" (
"occupation" varchar,
"slug" varchar,
"parent" varchar,
"total_number_workers" varchar,
"median_weekly_earnings" varchar,
"men_number_workers" varchar,
"men_median_weekly_earnings" varchar,
"women_number_workers" varchar,
"women_median_weekly_earnings" varchar,
"year" int
);
-- 2024-03-09 19:04:54.8300
ALTER TABLE "occupations"
ADD FOREIGN KEY ("parent_id") REFERENCES "occupations" ("id");
-- 2024-03-09 19:04:54.8440
CREATE UNIQUE INDEX occupation_slugs_unique ON occupations (slug);
-- 2024-03-09 19:04:54.8570
ALTER TABLE "wage_gaps"
ADD FOREIGN KEY ("occupation_id") REFERENCES "occupations" ("id");
-- 2024-03-09 19:04:54.8700
CREATE VIEW wage_gaps_view AS
SELECT
o1.name,
o1.slug,
o2.name AS parent_name,
wg.cents_to_dollar,
wg.year
FROM
occupations o1
INNER JOIN occupations o2 ON o1.parent_id = o2.id
INNER JOIN wage_gaps wg ON wg.occupation_id = o1.id
WHERE
cents_to_dollar IS NOT NULL
ORDER BY
cents_to_dollar DESC;
-- 2024-03-09 19:05:01.3390
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'occupations'
AND p.relkind = 'v';
-- 2024-03-09 19:05:01.3550
SELECT * FROM "public"."occupations" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 19:05:01.3560
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='occupations';
-- 2024-03-09 19:05:01.3560
SELECT COUNT(*) as count FROM "public"."occupations";
-- 2024-03-09 19:05:02.0020
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps'
AND p.relkind = 'v';
-- 2024-03-09 19:05:02.0170
SELECT * FROM "public"."wage_gaps" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 19:05:02.0180
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='wage_gaps';
-- 2024-03-09 19:05:02.0180
SELECT COUNT(*) as count FROM "public"."wage_gaps";
-- 2024-03-09 19:05:04.0220
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'weekly_earnings'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'weekly_earnings'
AND p.relkind = 'v';
-- 2024-03-09 19:05:04.0380
SELECT * FROM "public"."weekly_earnings" LIMIT 300 OFFSET 0;
-- 2024-03-09 19:05:04.0390
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='weekly_earnings';
-- 2024-03-09 19:05:04.0390
SELECT COUNT(*) as count FROM "public"."weekly_earnings";
-- 2024-03-09 19:06:38.4530
select pg_get_viewdef('"public"."wage_gaps_view"'::regclass, true) as create_statement;
-- 2024-03-09 19:06:38.4630
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps_view'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps_view'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps_view'
AND p.relkind = 'v';
-- 2024-03-09 19:06:38.4850
SELECT * FROM "public"."wage_gaps_view" LIMIT 300 OFFSET 0;
-- 2024-03-09 19:06:38.4850
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='wage_gaps_view';
-- 2024-03-09 19:06:38.4850
SELECT COUNT(*) as count FROM "public"."wage_gaps_view";
-- 2024-03-09 19:06:38.9180
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps'
AND p.relkind = 'v';
-- 2024-03-09 19:06:38.9330
SELECT * FROM "public"."wage_gaps" ORDER BY "id" LIMIT 300 OFFSET 0;
-- 2024-03-09 19:06:38.9330
select reltuples::int8 as count from pg_class c JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace where nspname='public'AND relname='wage_gaps';
-- 2024-03-09 19:06:38.9330
SELECT COUNT(*) as count FROM "public"."wage_gaps";
-- 2024-03-09 19:06:39.3610
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'wage_gaps'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'wage_gaps'
AND p.relkind = 'v';
-- 2024-03-09 19:06:40.0810
SELECT
pg_total_relation_size(relid) AS total_size,
pg_table_size(relid) AS data_size,
pg_indexes_size(relid) AS index_size,
obj_description(relid, 'pg_class') AS comment
FROM
pg_catalog.pg_statio_user_tables
WHERE
schemaname = 'public'
AND relname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_proc') AS comment
FROM
pg_catalog.pg_proc p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace
WHERE
n.nspname = 'public'
AND p.proname = 'occupations'
UNION
SELECT
NULL AS total_size,
NULL AS data_size,
NULL AS index_size,
obj_description(p.oid, 'pg_class') AS comment
FROM
pg_catalog.pg_class p
LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.relnamespace
WHERE
n.nspname = 'public'
AND p.relname = 'occupations'
AND p.relkind = 'v';
-- 2024-03-09 19:06:40.0970