-
Notifications
You must be signed in to change notification settings - Fork 1
/
MainBatchUpload.bat
2188 lines (2188 loc) · 190 KB
/
MainBatchUpload.bat
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
@echo off
rem *****UK TIMES standard outputs tool*****
rem version of TIMES model = uktm_model_v1.2.3_d0.1.2_DNP
rem DOS Batch file to construct SQL queries, run the code, amalgamate the results and tidy up (delete) the intermediate stages
rem version as filename. By Fernley Symons 8:02 PM 12 January, 2016
rem works by:
rem
rem 1) constructing SQL code file to create temp files from TIMES runs (creates one script entry for each file)
rem 2) adding analysis SQL to generate summaries which are output to CSVs
rem 3) amalgamates the CSVs
rem 4) deletes the intermediate CSVs leaving a single output file
rem
rem *** _Important note_: this will not work if the folder path has spaces (or other chars like '&' in it ***
rem
rem By Fernley Symons
rem *****Instructions for updating from "HumanReadableQueries.sql" in Notepad++*****
rem Things to bear in mind:
rem if '%' is part of a sql query (e.g. "like 'x%'), then % needs to be doubled "like 'x%%'"
rem Other characters (|, <, > etc) need to be escaped in a similar way with ^:- ^| etc
rem can't have very long lines - need to break statements
rem filename at end of line, no spaces afterwards
REM Also note that doesn't like labels (col names or values etc) which break across lines. Inserts a break into them so that they don't match any more
rem It will be rare that you'll need to change the first, dynamic bit of the script which creates one SQL statement set
rem for each VD file in the folder. These instructions ignore that and assume that block's unchanged.
rem 1) Copy the appropriate block of SQL from "Human..." to a blank doc
rem 2) Remove indentation from the copied text: select it and press shift-tab repeatedly to do this
rem 3) Comment lines starting "--" should be removed (comments starting "/*" retained). Do this by doing a regex search / replace for
rem "^--.+\r\n" (no quotes) replace with blank.
rem 4) Remove embedded comments [appearing on same line as code] with regex replace "--.+" with blank
rem 5) Remove extraneous blank lines with regex replace "(\r\n){2,}" with "\r\n"
rem 6) Make replacements for other reserved DOS words. See below for example (set "texta..." etc). In general there will only be a few of these; define more as needed
rem NB No need to replace "~" in output file locations since these are DOS commands meaning "put it in the same folder as this BAT file". "~" only needs replacing if part of a query
rem (i.e. regex in postgres). ****Note that the first 2 queries contain reserved words****
rem 7) Change the single "%" to double "%%" but leave filenames for copy statements unchanged. Regex replace "(%[^~])" with "%\1"
rem 8) Escape other characters: Regex replace "(\||<|>)" with "^\1"
rem 9) Regex replace "(.+)" with "echo \1 >> MainBatchUpload.sql"
rem 10) Regex replace "echo (\/\*.+\/)" with "rem \1\r\necho \1". This duplicates the header in a way which is more obvious to read in the BAT file
rem 11) Copy the edited text back over the body of the BAT below (below the upload statements and before the run SQL statement) and save file
rem 12) comment out the run SQL statement, run the BAT and check the SQL appears sensible.
rem 13) Uncomment the run SQL statement and use the file
rem ***********
rem 9:34 PM 19 January, 2016 Correction of error in new vehicles capacity script
rem 2:04 PM 01 February, 2016; addition of whole vehicle stock capacity
rem 2:58 PM 04 February, 2016; addition of new vehicle emissions intensity
rem 1:39 PM 08 February, 2016; correction of new vehicle emissions intensity
rem 3:30 PM 16 February, 2016; a slew of new queries, refactored code, re-ordered queries. Baseline version for git:-replaces v18
rem 7:50 PM 04 April, 2016: addition of final end use energy demand by main sector; renamed some analysis entities
rem 1:48 PM 12 April, 2016: addition of primary energy demand by main fuel
rem 8:47 PM 11 August, 2016: updated to reflect changes to elec gen techs
rem 11:53 AM 15 August, 2016: updated to reflect corrected and standardised set definitions
rem 8:52 PM 15 November, 2016: correction to FUEL TECHS AGR set in final energy query
rem 2:55 PM 15 December, 2016: BF edited Filter 131, 'heat-res_conserv' and Filter 146, 'new-heat-res_conserv'
rem 2:10 PM 16 December, 2016:
rem BF added 'RESMSWINO','RESMSWORG' to Filters 287,206,207,208 to match locations of equivalent service sector commodities 'SERMSWINO','SERMSWORG'
rem BF added 'RESMSWINO01','RESMSWORG01' to Filter 304 'Fuel Techs RES' to match equivalent locations of equivalent service sector Fuel Techs 'SERMSWINO01','SERMSWORG01'
rem 3:00 PM 16 December, 2016:
rem BF added residential EFW CHP, 'RCHPEA-EFW01','RCHPNA-EFW01' to Filters 79,114,303,335
rem BF added services EFW CHP, 'SCHP-EFW01' to Filters 79,114,230,368
REM 8:54 PM 12 January, 2017 FS: change to electrical storage query, other small changes to filter definitions (removal of cast to varchar)
REM 1:26 PM 06 February, 2017 FS: various updates to reflect revised human readable
REM 6:19 PM 23 February, 2017 FS: various updates to reflect human readable, change to instructions for how to produce this file (above)
rem 9:01 PM 09 March, 2017 FS: update to human readable
rem ***********
echo processing vd files...
@echo off
rem The following allows us to insert text which is otherwise outlawed in DOS:
setlocal enableDelayedExpansion
rem delete the SQL script if it exists - code below (re-) generates it.
IF EXIST MainBatchUpload.sql del /F MainBatchUpload.sql
rem need to define some variables which contain DOS reserved words. These are replaced by the preprocessor in the script:
set "texta=IF"
set "textb=IF NOT"
set "textc=~"
set "textd=^"
set "texte=&"
rem this block creates the 2 temp table definitions. First stores the unformatted data from the VD file, second parses this into fields and inserts into the "vedastore" table against which the
rem queries are run.
echo CREATE temp TABLE !textb! EXISTS vedastore( tablename varchar(100), id serial, attribute varchar(50), commodity varchar(50), process varchar(50), period varchar(50), region varchar(50), vintage varchar(50), timeslice varchar(50), userconstraint varchar(50), pv numeric ); drop table !texta! exists veda; create temp table veda( id serial, stuff varchar(1000) ); >> MainBatchUpload.sql
rem the following creates a block of sql for each VD file to upload it, delete the header rows and break the entries into fields
for /f "delims=|" %%i in ('dir /b *.vd') do echo delete from veda; ALTER SEQUENCE veda_id_seq RESTART WITH 1; copy veda (stuff) from '%%~fi'; insert into vedastore (tablename, attribute ,commodity ,process ,period ,region ,vintage ,timeslice ,userconstraint ,pv) select '%%~ni', trim(both '"' from a[1]), trim(both '"' from a[2]), trim(both '"' from a[3]), trim(both '"' from a[4]), trim(both '"' from a[5]), trim(both '"' from a[6]), trim(both '"' from a[7]), trim(both '"' from a[8]), cast(a[9] as numeric) from ( select string_to_array(stuff, ',') from veda order by id offset 13 ) as dt(a); >> MainBatchUpload.sql
rem /* *Dummy imports by table* */echo /* *Dummy imports by table* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select 'dummies' ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| 'Cost_Act' ^|^| '^|' ^|^| 'various' ^|^| '^|various'::varchar(300) "id", >> MainBatchUpload.sql
echo 'dummies'::varchar(300) "analysis", tablename, 'Cost_Act'::varchar(50) "attribute", >> MainBatchUpload.sql
echo 'various'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where process in('IMPDEMZ','IMPMATZ','IMPNRGZ') and attribute = 'Cost_Act' >> MainBatchUpload.sql
echo group by tablename >> MainBatchUpload.sql
echo order by tablename, analysis >> MainBatchUpload.sql
echo ) TO '%~dp0dummiesout.csv' delimiter ',' CSV HEADER; >> MainBatchUpload.sql
rem /* *All GHG emissions* */echo /* *All GHG emissions* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select 'ghg_all^|' ^|^| tablename ^|^| '^|Var_FOut^|' ^|^| commodity ^|^| '^|all'::varchar(300) "id", >> MainBatchUpload.sql
echo 'ghg_all'::varchar(50) "analysis", >> MainBatchUpload.sql
echo tablename, >> MainBatchUpload.sql
echo 'Var_FOut'::varchar(50) "attribute", >> MainBatchUpload.sql
echo commodity, >> MainBatchUpload.sql
echo 'all'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='VAR_FOut' and commodity in('GHG-ETS-NO-IAS-NET','GHG-ETS-NO-IAS-TER','GHG-ETS-YES-IAS-NET','GHG-ETS-YES-IAS-TER', >> MainBatchUpload.sql
echo 'GHG-NO-IAS-YES-LULUCF-NET','GHG-NO-IAS-YES-LULUCF-TER','GHG-NON-ETS-YES-LULUCF-NET','GHG-NON-ETS-YES-LULUCF-TER', >> MainBatchUpload.sql
echo 'GHG-YES-IAS-YES-LULUCF-NET','GHG-YES-IAS-YES-LULUCF-TER','GHG-NO-AS-YES-LULUCF-NET') >> MainBatchUpload.sql
echo group by tablename, commodity >> MainBatchUpload.sql
echo order by tablename, commodity >> MainBatchUpload.sql
echo ) TO '%~dp0GHGOut.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *GHG emissions by sector* */echo /* *GHG emissions by sector* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select analysis ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| attribute ^|^| '^|' ^|^| commodity ^|^| '^|' ^|^| process::varchar(300) "id", analysis, tablename,attribute, >> MainBatchUpload.sql
echo commodity, process, >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select 'all'::varchar(50) "process", period, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when attribute='VAR_FIn' and commodity in('Traded-Emission-ETS','PRCCH4P') then -pv >> MainBatchUpload.sql
echo else pv >> MainBatchUpload.sql
echo end as pv, >> MainBatchUpload.sql
echo tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when commodity in('Traded-Emission-ETS','PRCCO2P','PRCCH4P','PRCN2OP') then 'various' >> MainBatchUpload.sql
echo else attribute >> MainBatchUpload.sql
echo end as attribute, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when commodity in('PRCCO2P', 'PRCCH4N', 'PRCCH4P', 'PRCN2ON', 'PRCN2OP') then 'various' >> MainBatchUpload.sql
echo else commodity >> MainBatchUpload.sql
echo end as "commodity", >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when commodity='Traded-Emission-ETS' then 'ghg_sec-traded-emis-ets' >> MainBatchUpload.sql
echo when commodity in('GHG-ELC','GHG-IND-ETS','GHG-RES-ETS','GHG-SER-ETS','GHG-OTHER-ETS','GHG-IAS-ETS', >> MainBatchUpload.sql
echo 'GHG-IAS-NON-ETS','GHG-IND-NON-ETS','GHG-RES-NON-ETS','GHG-SER-NON-ETS','GHG-TRA-NON-ETS-NO-AS', >> MainBatchUpload.sql
echo 'GHG-AGR-NO-LULUCF','GHG-OTHER-NON-ETS','GHG-LULUCF','GHG-HFC-NON-ETS','Traded-Emission-Non-ETS','GHG-ELC-CAPTURED','GHG-IND-ETS-CAPTURED', >> MainBatchUpload.sql
echo 'GHG-IND-NON-ETS-CAPTURED','GHG-OTHER-ETS-CAPTURED','GHG-DAS-ETS','GHG-DAS-NON-ETS') then 'ghg_sec-main-secs' >> MainBatchUpload.sql
echo when commodity in('PRCCH4N','PRCN2ON') then 'ghg_sec-prc-non-waste-non-ets' >> MainBatchUpload.sql
echo when commodity in('PRCCO2P','PRCCH4P','PRCN2OP') then 'ghg_sec-prc-waste-non-ets' >> MainBatchUpload.sql
echo when commodity ='PRCCO2N' then 'ghg_sec-prc-ets' >> MainBatchUpload.sql
echo end as "analysis" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where (attribute='VAR_FOut' and commodity in('GHG-ELC','GHG-IND-ETS','GHG-RES-ETS','GHG-SER-ETS','GHG-OTHER-ETS', >> MainBatchUpload.sql
echo 'GHG-IAS-ETS','GHG-IAS-NON-ETS','Traded-Emission-ETS','GHG-IND-NON-ETS','GHG-RES-NON-ETS', >> MainBatchUpload.sql
echo 'GHG-SER-NON-ETS','GHG-TRA-NON-ETS-NO-AS','GHG-AGR-NO-LULUCF','GHG-OTHER-NON-ETS','GHG-LULUCF','GHG-HFC-NON-ETS', >> MainBatchUpload.sql
echo 'Traded-Emission-Non-ETS','GHG-ELC-CAPTURED','GHG-IND-ETS-CAPTURED','GHG-IND-NON-ETS-CAPTURED', >> MainBatchUpload.sql
echo 'GHG-OTHER-ETS-CAPTURED','PRCCO2P','PRCCH4N','PRCCH4P','PRCN2ON','PRCN2OP', >> MainBatchUpload.sql
echo 'PRCCO2N','GHG-DAS-ETS','GHG-DAS-NON-ETS')) or (attribute='VAR_FIn' and commodity in('Traded-Emission-ETS','PRCCH4P')) >> MainBatchUpload.sql
echo order by period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where analysis ^<^>'' >> MainBatchUpload.sql
echo group by id, analysis,tablename, attribute, commodity,process >> MainBatchUpload.sql
echo order by tablename, analysis, attribute, commodity >> MainBatchUpload.sql
echo ) TO '%~dp0GHGsectorOut.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *GHG and sequestered emissions by industry sub-sector* */echo /* *GHG and sequestered emissions by industry sub-sector* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select 'ghg_ind-subsec-'^|^|sector ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| 'VAR_FOut' ^|^| '^|' ^|^| 'various' ^|^| '^|various'::varchar(300) "id", >> MainBatchUpload.sql
echo 'ghg_ind-subsec-'^|^|sector::varchar(300) "analysis", tablename, 'VAR_Fout'::varchar(50) "attribute", >> MainBatchUpload.sql
echo 'various'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from( >> MainBatchUpload.sql
echo select tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when left(process,3)='ICH' then 'ich' >> MainBatchUpload.sql
echo when left(process,3)='ICM' then 'icm' >> MainBatchUpload.sql
echo when left(process,3)='IFD' then 'ifd' >> MainBatchUpload.sql
echo when left(process,3)='IIS' then 'iis' >> MainBatchUpload.sql
echo when left(process,3)='INF' then 'inf' >> MainBatchUpload.sql
echo when left(process,3)='INM' then 'inm' >> MainBatchUpload.sql
echo when left(process,3)='IOI' or process like 'INDHFCOTH0%%' then 'ioi' >> MainBatchUpload.sql
echo when left(process,3)='IPP' then 'ipp' >> MainBatchUpload.sql
echo when process='-' then 'other' >> MainBatchUpload.sql
echo else null >> MainBatchUpload.sql
echo end "sector", >> MainBatchUpload.sql
echo period, sum(case when commodity in('SKNINDCO2N','SKNINDCO2P') then -pv else pv end) "pv" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where commodity in ('SKNINDCO2N','SKNINDCO2P','INDCO2N','INDCO2P','INDNEUCO2N','INDCH4N','INDN2ON','INDHFCP') and attribute='VAR_FOut' >> MainBatchUpload.sql
echo group by tablename, sector,period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where sector is not null >> MainBatchUpload.sql
echo group by tablename, sector >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select 'ghgseq_ind-subsec-'^|^|sector ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| 'VAR_FOut' ^|^| '^|' ^|^| 'various' ^|^| '^|various'::varchar(300) "id", >> MainBatchUpload.sql
echo 'ghgseq_ind-subsec-'^|^|sector::varchar(300) "analysis", tablename, 'VAR_Fout'::varchar(50) "attribute", >> MainBatchUpload.sql
echo 'various'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from( >> MainBatchUpload.sql
echo select tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when left(process,3)='ICH' then 'ich' >> MainBatchUpload.sql
echo when left(process,3)='ICM' then 'icm' >> MainBatchUpload.sql
echo when left(process,3)='IFD' then 'ifd' >> MainBatchUpload.sql
echo when left(process,3)='IIS' then 'iis' >> MainBatchUpload.sql
echo when left(process,3)='INF' then 'inf' >> MainBatchUpload.sql
echo when left(process,3)='INM' then 'inm' >> MainBatchUpload.sql
echo when left(process,3)='IOI' or process like 'INDHFCOTH0%%' then 'ioi' >> MainBatchUpload.sql
echo when left(process,3)='IPP' then 'ipp' >> MainBatchUpload.sql
echo when process='-' then 'other' >> MainBatchUpload.sql
echo else null >> MainBatchUpload.sql
echo end "sector", >> MainBatchUpload.sql
echo period, sum(case when commodity in('SKNINDCO2N','SKNINDCO2P') then -pv else pv end) "pv" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where commodity in ('SKNINDCO2N','SKNINDCO2P') and attribute='VAR_FOut' >> MainBatchUpload.sql
echo group by tablename, sector,period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where sector is not null >> MainBatchUpload.sql
echo group by tablename, sector >> MainBatchUpload.sql
echo ) TO '%~dp0IndSubGHG.csv' CSV; >> MainBatchUpload.sql
rem /* *Electricity generation by source* */echo /* *Electricity generation by source* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo with emissions_chp as ( >> MainBatchUpload.sql
echo select tablename, proc_set, commodity,period,sum(pv) "pv" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select period, pv,commodity,process,tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('ICHCHPBIOG01','ICHCHPBIOS00','ICHCHPBIOS01','ICHCHPCCGT01','ICHCHPCCGTH01','ICHCHPCOA00','ICHCHPCOA01','ICHCHPFCH01','ICHCHPGT01','ICHCHPHFO00','ICHCHPLFO00','ICHCHPLPG00' >> MainBatchUpload.sql
echo ,'ICHCHPLPG01','ICHCHPNGA00','ICHCHPPRO00','ICHCHPPRO01','IFDCHPBIOG01','IFDCHPBIOS00','IFDCHPBIOS01','IFDCHPCCGT01','IFDCHPCCGTH01','IFDCHPCOA00','IFDCHPCOA01','IFDCHPFCH01' >> MainBatchUpload.sql
echo ,'IFDCHPGT01','IFDCHPHFO00','IFDCHPLFO00','IFDCHPNGA00','IISCHPBFG00','IISCHPBFG01','IISCHPBIOG01','IISCHPBIOS01','IISCHPCCGT01','IISCHPCCGTH01','IISCHPCOG00','IISCHPCOG01' >> MainBatchUpload.sql
echo ,'IISCHPFCH01','IISCHPGT01','IISCHPHFO00','IISCHPNGA00','INMCHPBIOG01','INMCHPBIOS01','INMCHPCCGT01','INMCHPCCGTH01','INMCHPCOA01','INMCHPCOG00','INMCHPCOG01','INMCHPFCH01' >> MainBatchUpload.sql
echo ,'INMCHPGT01','INMCHPNGA00','IOICHPBIOG01','IOICHPBIOS00','IOICHPBIOS01','IOICHPCCGT01','IOICHPCCGTH01','IOICHPCOA01','IOICHPFCH01','IOICHPGT01','IOICHPHFO00','IOICHPNGA00' >> MainBatchUpload.sql
echo ,'IPPCHPBIOG01','IPPCHPBIOS00','IPPCHPBIOS01','IPPCHPCCGT01','IPPCHPCCGTH01','IPPCHPCOA00','IPPCHPCOA01','IPPCHPFCH01','IPPCHPGT01','IPPCHPNGA00','IPPCHPWST00','IPPCHPWST01') >> MainBatchUpload.sql
echo then 'CHP IND SECTOR' >> MainBatchUpload.sql
echo when process in('PCHP-CCP00','PCHP-CCP01') then 'CHP PRC SECTOR' >> MainBatchUpload.sql
echo when process in('SCHP-ADM01','SCHP-CCG00','SCHP-CCG01', >> MainBatchUpload.sql
echo 'SCHP-CCH01','SCHP-FCH01','SCHP-GES00','SCHP-GES01', >> MainBatchUpload.sql
echo 'SCHP-STM01','SCHP-STW00','SCHP-STW01','SHLCHPRG01', >> MainBatchUpload.sql
echo 'SHLCHPRH01','SHLCHPRW01','SCHP-EFW01') then 'CHP SER SECTOR' >> MainBatchUpload.sql
echo when process in('UCHP-CCG00','UCHP-CCG01') then 'CHP UPS SECTOR' >> MainBatchUpload.sql
echo when process in('RHEACHPRG01','RHEACHPRH01','RHEACHPRW01', >> MainBatchUpload.sql
echo 'RHFCCHPRG01','RHFCCHPRH01','RHFCCHPRW01','RHFSCHPRG01', >> MainBatchUpload.sql
echo 'RHFSCHPRH01','RHFSCHPRW01','RHHCCHPRG01','RHHCCHPRH01', >> MainBatchUpload.sql
echo 'RHHCCHPRW01','RHHSCHPRG01','RHHSCHPRH01','RHHSCHPRW01', >> MainBatchUpload.sql
echo 'RHNACHPRG01','RHNACHPRH01','RHNACHPRW01' >> MainBatchUpload.sql
echo ) then 'CHP RES MICRO' >> MainBatchUpload.sql
echo end proc_set >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='VAR_FOut' and commodity in('RESCH4N','SERN2ON','INDCO2N','SERCH4N','INDCH4N','INDN2ON','UPSN2ON','UPSCO2N','UPSCH4N','PRCCH4N','PRCCO2N','PRCN2ON' >> MainBatchUpload.sql
echo ,'SERCO2N','RESCO2N','RESN2ON') >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select period, pv,commodity,process,tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('ICHCHPBIOG01','ICHCHPBIOS00','ICHCHPBIOS01','IFDCHPBIOG01','IFDCHPBIOS00','IFDCHPBIOS01','IISCHPBIOG01','IISCHPBIOS01','INMCHPBIOG01','INMCHPBIOS01','IOICHPBIOG01' >> MainBatchUpload.sql
echo ,'IOICHPBIOS00','IOICHPBIOS01','IPPCHPBIOG01','IPPCHPBIOS00','IPPCHPBIOS01','IPPCHPWST00','IPPCHPWST01') then 'CHP IND BIO' >> MainBatchUpload.sql
echo when process in('SCHP-ADM01','SCHP-GES00','SCHP-GES01','SCHP-STM01','SCHP-STW00','SCHP-STW01','SHLCHPRW01','SCHP-EFW01') then 'CHP SER BIO' >> MainBatchUpload.sql
echo when process in('SHLCHPRG01','SHLCHPRH01','SHLCHPRW01') then 'CHP SER MICRO' >> MainBatchUpload.sql
echo when process in('RCHPEA-CCG00','RCHPEA-CCG01','RCHPEA-CCH01', >> MainBatchUpload.sql
echo 'RCHPEA-FCH01','RCHPEA-STW01','RCHPNA-CCG01','RCHPNA-CCH01', >> MainBatchUpload.sql
echo 'RCHPNA-FCH01','RCHPNA-STW01','RHEACHPRG01','RHEACHPRH01', >> MainBatchUpload.sql
echo 'RHEACHPRW01','RHNACHPRG01','RHNACHPRH01','RHNACHPRW01', >> MainBatchUpload.sql
echo 'RCHPEA-EFW01','RCHPNA-EFW01','RHFCCHPRH01','RHFSCHPRH01', >> MainBatchUpload.sql
echo 'RHHCCHPRH01','RHHSCHPRH01','RHFCCHPRG01','RHFSCHPRG01', >> MainBatchUpload.sql
echo 'RHHCCHPRG01','RHHSCHPRG01','RHFCCHPRW01','RHFSCHPRW01', >> MainBatchUpload.sql
echo 'RHHCCHPRW01','RHHSCHPRW01') then 'CHP RES SECTOR' >> MainBatchUpload.sql
echo else null >> MainBatchUpload.sql
echo end proc_set >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='VAR_FOut' and commodity in('RESCH4N','SERN2ON','INDCO2N','SERCH4N','INDCH4N','INDN2ON','UPSN2ON','UPSCO2N','UPSCH4N','PRCCH4N','PRCCO2N','PRCN2ON' >> MainBatchUpload.sql
echo ,'SERCO2N','RESCO2N','RESN2ON') >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where proc_set is not null >> MainBatchUpload.sql
echo group by tablename, proc_set, commodity,period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , emis_co2_sector as( >> MainBatchUpload.sql
echo select tablename, comm_set, >> MainBatchUpload.sql
echo commodity,period, pv >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select case >> MainBatchUpload.sql
echo when commodity in('AGRCO2N','AGRCO2P') then 'EMIS CO2 AGR' >> MainBatchUpload.sql
echo when commodity in('ELCCO2N') then 'EMIS CO2 ELC' >> MainBatchUpload.sql
echo when commodity in('HYGCO2N') then 'EMIS CO2 HYG' >> MainBatchUpload.sql
echo when commodity in('INDCO2N','INDCO2P') then 'EMIS CO2 IND' >> MainBatchUpload.sql
echo when commodity in('INDNEUCO2N') then 'EMIS CO2 NEU' >> MainBatchUpload.sql
echo when commodity in('PRCCO2N','PRCCO2P') then 'EMIS CO2 PRC' >> MainBatchUpload.sql
echo when commodity in('RESCO2N') then 'EMIS CO2 RES' >> MainBatchUpload.sql
echo when commodity in('SERCO2N') then 'EMIS CO2 SER' >> MainBatchUpload.sql
echo when commodity in('TRACO2N') then 'EMIS CO2 TRA' >> MainBatchUpload.sql
echo when commodity in('UPSCO2N','UPSCO2P') then 'EMIS CO2 UPS' >> MainBatchUpload.sql
echo end as comm_set,commodity,pv,period,tablename >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='VAR_FOut' >> MainBatchUpload.sql
echo ) a where comm_set is not null >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , emis_ghg_dif as ( >> MainBatchUpload.sql
echo select tablename, comm_set, >> MainBatchUpload.sql
echo commodity,period,pv >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select case >> MainBatchUpload.sql
echo when commodity in ('AGRCH4N','AGRCH4P','AGRCO2N','AGRCO2P','AGRHFCN','AGRHFCP','AGRN2ON','AGRN2OP','AGRNH3','AGRNOX','AGRPM10','AGRPM25','AGRSO2','AGRVOC') then 'EMIS GHG AGR' >> MainBatchUpload.sql
echo when commodity in ('ELCCH4N','ELCCH4P','ELCCO2N','ELCCO2P','ELCHFCN','ELCHFCP','ELCN2ON','ELCN2OP','ELCNH3','ELCNOX','ELCPM10','ELCPM25','ELCSO2','ELCVOC') then 'EMIS GHG ELC' >> MainBatchUpload.sql
echo when commodity in ('HYGCH4N','HYGCH4P','HYGCO2N','HYGCO2P','HYGHFCN','HYGHFCP','HYGN2ON','HYGN2OP','HYGNH3','HYGNOX','HYGPM10','HYGPM25','HYGSO2','HYGVOC') then 'EMIS GHG HYG' >> MainBatchUpload.sql
echo when commodity in ('INDCH4N','INDCH4P','INDCO2N','INDCO2P','INDHFCN','INDHFCP','INDN2ON','INDN2OP') then 'EMIS GHG IND' >> MainBatchUpload.sql
echo when commodity in ('INDNEUCO2N') then 'EMIS GHG NEU' >> MainBatchUpload.sql
echo when commodity in ('PRCCH4N','PRCCH4P','PRCCO2N','PRCCO2P','PRCHFCN','PRCHFCP','PRCN2ON','PRCN2OP','PRCNH3','PRCNOX','PRCPM10','PRCPM25','PRCSO2','PRCVOC') then 'EMIS GHG PRC' >> MainBatchUpload.sql
echo when commodity in ('RESCH4N','RESCH4P','RESCO2N','RESCO2P','RESHFCN','RESHFCP','RESN2ON','RESN2OP','RESNH3','RESNOX','RESPM10','RESPM25','RESSO2','RESVOC') then 'EMIS GHG RES' >> MainBatchUpload.sql
echo when commodity in ('SERCH4N','SERCH4P','SERCO2N','SERCO2P','SERHFCN','SERHFCP','SERN2ON','SERN2OP','SERNH3','SERNOX','SERPM10','SERPM25','SERSO2','SERVOC') then 'EMIS GHG SER' >> MainBatchUpload.sql
echo when commodity in ('TRACH4N','TRACH4P','TRACO2N','TRACO2P','Traded-Emission-ETS','Traded-Emission-Non-ETS','TRAHFCN','TRAHFCP','TRAN2ON','TRAN2OP','TRANH3','TRANOX','TRAPM10' >> MainBatchUpload.sql
echo ,'TRAPM25','TRASO2','TRAVOC') then 'EMIS GHG TRA' >> MainBatchUpload.sql
echo when commodity in ('UPSCH4N','UPSCH4P','UPSCO2N','UPSCO2P','UPSHFCN','UPSHFCP','UPSN2ON','UPSN2OP') then 'EMIS GHG UPS' >> MainBatchUpload.sql
echo end as comm_set,commodity,pv,period, tablename >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute in('EQ_Combal','VAR_Comnet') >> MainBatchUpload.sql
echo ) a where comm_set is not null >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , "elc-emis" as( >> MainBatchUpload.sql
echo select >> MainBatchUpload.sql
echo tablename,period,sum(pv)/1000 "elc-emis" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename,pv,period from "emis_co2_sector" where comm_set='EMIS CO2 ELC' >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select tablename,pv,period from "emis_ghg_dif" >> MainBatchUpload.sql
echo where commodity in('ELCCH4N','ELCN2ON') >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select tablename,sum(pv) "pv", period from "emissions_chp" >> MainBatchUpload.sql
echo where proc_set in('CHP IND SECTOR','CHP PRC SECTOR','CHP RES SECTOR','CHP SER SECTOR','CHP UPS SECTOR') and >> MainBatchUpload.sql
echo commodity in('INDCO2N','INDCH4N','INDN2ON','PRCCO2N','PRCCH4N','PRCN2ON','RESCO2N','RESCH4N','RESN2ON','SERCO2N','SERCH4N','SERN2ON','UPSCO2N','UPSCH4N','UPSN2ON') >> MainBatchUpload.sql
echo group by tablename, period >> MainBatchUpload.sql
echo ) a group by tablename,period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , elc_prd_fuel as ( >> MainBatchUpload.sql
echo select >> MainBatchUpload.sql
echo proc_set,tablename,period, sum(pv) "pv" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select >> MainBatchUpload.sql
echo tablename,period, pv, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('EBIO01','EBIOCON00','EBIOS00','EBOG-ADE01','EBOG-LFE00','EBOG-LFE01','EBOG-SWE00','EBOG-SWE01','EMSW00','EMSW01','EPOLWST00','ESTWWST00' >> MainBatchUpload.sql
echo ,'ESTWWST01') then 'ELC FROM BIO' >> MainBatchUpload.sql
echo when process in('EBIOQ01') then 'ELC FROM BIO CCS' >> MainBatchUpload.sql
echo when process in('PCHP-CCP00','PCHP-CCP01','UCHP-CCG00','UCHP-CCG01') then 'ELC FROM CHP' >> MainBatchUpload.sql
echo when process='ECOAQR01' then 'ELC FROM COAL CCSRET' >> MainBatchUpload.sql
echo when process in('ECOARR01') then 'ELC FROM COAL RR' >> MainBatchUpload.sql
echo when process in('ECOA00','ECOABIO00') then 'ELC FROM COAL-COF' >> MainBatchUpload.sql
echo when process in('ECOAQ01','ECOAQDEMO01') then 'ELC FROM COALCOF CCS' >> MainBatchUpload.sql
echo when process in('ENGACCT00','ENGAOCT00','ENGAOCT01','ENGARCPE00','ENGARCPE01') then 'ELC FROM GAS' >> MainBatchUpload.sql
echo when process in('ENGACCTQ01','ENGACCTQDEMO01') then 'ELC FROM GAS CCS' >> MainBatchUpload.sql
echo when process='ENGAQR01' then 'ELC FROM GAS CCSRET' >> MainBatchUpload.sql
echo when process in('ENGACCTRR01') then 'ELC FROM GAS RR' >> MainBatchUpload.sql
echo when process in('EGEO01') then 'ELC FROM GEO' >> MainBatchUpload.sql
echo when process in('EHYD00','EHYD01') then 'ELC FROM HYDRO' >> MainBatchUpload.sql
echo when process in('EHYGCCT01','EHYGOCT01') then 'ELC FROM HYDROGEN' >> MainBatchUpload.sql
echo when process in('ELCIE00','ELCIE01','ELCII00','ELCII01') then 'ELC FROM IMPORTS' >> MainBatchUpload.sql
echo when process in('EMANOCT00','EMANOCT01') then 'ELC FROM MANFUELS' >> MainBatchUpload.sql
echo when process in('ENUCPWR00','ENUCPWR101','ENUCPWR102') then 'ELC FROM NUCLEAR' >> MainBatchUpload.sql
echo when process in('EDSTRCPE00','EDSTRCPE01','EHFOIGCC01','EOILL00','EOILL01','EOILS00','EOILS01') then 'ELC FROM OIL' >> MainBatchUpload.sql
echo when process in('EHFOIGCCQ01') then 'ELC FROM OIL CCS' >> MainBatchUpload.sql
echo when process in('ESOL00','ESOL01','ESOLPV00','ESOLPV01') then 'ELC FROM SOL-PV' >> MainBatchUpload.sql
echo when process in('ETIB101','ETIR101','ETIS101') then 'ELC FROM TIDAL' >> MainBatchUpload.sql
echo when process in('EWAV101') then 'ELC FROM WAVE' >> MainBatchUpload.sql
echo when process in('EWNDOFF00','EWNDOFF101','EWNDOFF201') then 'ELC FROM WIND-OFFSH' >> MainBatchUpload.sql
echo when process in('EWNDONS00','EWNDONS101','EWNDONS201') then 'ELC FROM WIND-ONSH' >> MainBatchUpload.sql
echo when process in('ELCEE00','ELCEE01','ELCEI00','ELCEI01') then 'ELC TO EXPORTS' >> MainBatchUpload.sql
echo end as proc_set >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='VAR_FOut' and commodity in('ELCDUMMY','ELC','ELC-E-IRE','ELC-E-EU','ELCGEN') >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where proc_set is not null >> MainBatchUpload.sql
echo group by tablename, period,proc_set >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select proc_set,tablename,period, sum(pv) "pv" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename,period, pv, >> MainBatchUpload.sql
echo case when process in('ICHCHPBIOG01','ICHCHPBIOS00','ICHCHPBIOS01', >> MainBatchUpload.sql
echo 'ICHCHPCCGT01','ICHCHPCCGTH01','ICHCHPCOA00','ICHCHPCOA01', >> MainBatchUpload.sql
echo 'ICHCHPFCH01','ICHCHPGT01','ICHCHPHFO00','ICHCHPLFO00', >> MainBatchUpload.sql
echo 'ICHCHPLPG00','ICHCHPLPG01','ICHCHPNGA00','ICHCHPPRO00', >> MainBatchUpload.sql
echo 'ICHCHPPRO01','IFDCHPBIOG01','IFDCHPBIOS00','IFDCHPBIOS01', >> MainBatchUpload.sql
echo 'IFDCHPCCGT01','IFDCHPCCGTH01','IFDCHPCOA00','IFDCHPCOA01', >> MainBatchUpload.sql
echo 'IFDCHPFCH01','IFDCHPGT01','IFDCHPHFO00','IFDCHPLFO00', >> MainBatchUpload.sql
echo 'IFDCHPNGA00','IISCHPBFG00','IISCHPBFG01','IISCHPBIOG01', >> MainBatchUpload.sql
echo 'IISCHPBIOS01','IISCHPCCGT01','IISCHPCCGTH01','IISCHPCOG00', >> MainBatchUpload.sql
echo 'IISCHPCOG01','IISCHPFCH01','IISCHPGT01','IISCHPHFO00', >> MainBatchUpload.sql
echo 'IISCHPNGA00','INMCHPBIOG01','INMCHPBIOS01','INMCHPCCGT01', >> MainBatchUpload.sql
echo 'INMCHPCCGTH01','INMCHPCOA01','INMCHPCOG00','INMCHPCOG01', >> MainBatchUpload.sql
echo 'INMCHPFCH01','INMCHPGT01','INMCHPNGA00','IOICHPBIOG01', >> MainBatchUpload.sql
echo 'IOICHPBIOS00','IOICHPBIOS01','IOICHPCCGT01','IOICHPCCGTH01', >> MainBatchUpload.sql
echo 'IOICHPCOA01','IOICHPFCH01','IOICHPGT01','IOICHPHFO00', >> MainBatchUpload.sql
echo 'IOICHPNGA00','IPPCHPBIOG01','IPPCHPBIOS00','IPPCHPBIOS01', >> MainBatchUpload.sql
echo 'IPPCHPCCGT01','IPPCHPCCGTH01','IPPCHPCOA00','IPPCHPCOA01', >> MainBatchUpload.sql
echo 'IPPCHPFCH01','IPPCHPGT01','IPPCHPNGA00','IPPCHPWST00', >> MainBatchUpload.sql
echo 'IPPCHPWST01','PCHP-CCP00','PCHP-CCP01','RCHPEA-CCG00', >> MainBatchUpload.sql
echo 'RCHPEA-CCG01','RCHPEA-CCH01','RCHPEA-FCH01','RCHPEA-STW01', >> MainBatchUpload.sql
echo 'RCHPNA-CCG01','RCHPNA-CCH01','RCHPNA-FCH01','RCHPNA-STW01', >> MainBatchUpload.sql
echo 'RHEACHPRG01','RHEACHPRH01','RHEACHPRW01','RHNACHPRG01', >> MainBatchUpload.sql
echo 'RHNACHPRH01','RHNACHPRW01','RCHPEA-EFW01','RCHPNA-EFW01', >> MainBatchUpload.sql
echo 'SCHP-ADM01','SCHP-CCG00','SCHP-CCG01','SCHP-CCH01', >> MainBatchUpload.sql
echo 'SCHP-FCH01','SCHP-GES00','SCHP-GES01','SCHP-STM01', >> MainBatchUpload.sql
echo 'SCHP-STW00','SCHP-STW01','SHLCHPRG01','SHLCHPRH01', >> MainBatchUpload.sql
echo 'SHLCHPRW01','SCHP-EFW01','UCHP-CCG00','UCHP-CCG01', >> MainBatchUpload.sql
echo 'RHFCCHPRH01','RHFSCHPRH01','RHHCCHPRH01','RHHSCHPRH01', >> MainBatchUpload.sql
echo 'RHFCCHPRG01','RHFSCHPRG01','RHHCCHPRG01','RHHSCHPRG01', >> MainBatchUpload.sql
echo 'RHFCCHPRW01','RHFSCHPRW01','RHHCCHPRW01','RHHSCHPRW01') then 'elec-gen_chp' else null >> MainBatchUpload.sql
echo end proc_set >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where period in('2010','2011','2012','2015','2020','2025','2030','2035','2040','2045','2050','2055','2060') and attribute='VAR_FOut' >> MainBatchUpload.sql
echo and commodity in('ELCGEN','INDELC','RESELC','RESHOUSEELC','SERBUILDELC','SERDISTELC','SERELC') >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where proc_set is not null >> MainBatchUpload.sql
echo group by tablename, period,proc_set >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select proc_set,tablename,period, sum(pv) "pv" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename,period, pv, >> MainBatchUpload.sql
echo case when process='EWSTHEAT-OFF-01' then 'elec-gen_waste-heat-penalty' else null >> MainBatchUpload.sql
echo end::varchar(50) proc_set >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where period in('2010','2011','2012','2015','2020','2025','2030','2035','2040','2045','2050','2055','2060') and commodity = 'ELCGEN' and attribute = 'VAR_FIn' >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where proc_set is not null >> MainBatchUpload.sql
echo group by tablename, period,proc_set >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , cofiring_fuel as( >> MainBatchUpload.sql
echo select tablename, fuel, period, sum(pv) "pv" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename,commodity "fuel",period,pv >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where process in('ECOA00','ECOABIO00','ECOAQ01','ECOARR01','ECOAQDEMO01') and attribute='VAR_FIn' >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select tablename,commodity "fuel",period,pv >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where commodity in ('ELCBIOLFO','ELCBIOOIL','ELCHFO','ELCLFO','ELCLPG') and attribute='VAR_FIn' >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select tablename,commodity "fuel",period,pv >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where commodity in('ELCMAINSBOM','ELCMAINSGAS','ELCTRANSBOM','ELCTRANSGAS') and attribute='VAR_FIn' >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo group by tablename, fuel,period >> MainBatchUpload.sql
echo order by fuel, period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , cofiring_fuel_percents as( >> MainBatchUpload.sql
echo select tablename, period, >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel='ELCCOA' then pv else 0 end) / sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "coal", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCBIOCOA','ELCBIOCOA2','ELCPELL') then pv else 0 end) / sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "biocoal", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCMSC') then pv else 0 end) / sum(case when fuel in('ELCCOA','ELCBIOCOA','ELCBIOCOA2','ELCPELL','ELCMSC') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "oilcoal", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCHFO','ELCLFO','ELCLPG','ELCBIOOIL','ELCBIOLFO') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCHFO','ELCLFO','ELCLPG') then pv else 0 end) / sum(case when fuel in('ELCHFO','ELCLFO','ELCLPG','ELCBIOOIL','ELCBIOLFO') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "oil", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCHFO','ELCLFO','ELCLPG','ELCBIOOIL','ELCBIOLFO') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCBIOOIL','ELCBIOLFO') then pv else 0 end) / sum(case when fuel in('ELCHFO','ELCLFO','ELCLPG','ELCBIOOIL','ELCBIOLFO') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "biooil", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCMAINSGAS','ELCTRANSGAS','ELCMAINSBOM','ELCTRANSBOM') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCMAINSGAS','ELCTRANSGAS') then pv else 0 end) / sum(case when fuel in('ELCMAINSGAS','ELCTRANSGAS','ELCMAINSBOM','ELCTRANSBOM') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "gas", >> MainBatchUpload.sql
echo case when sum(case when fuel in('ELCMAINSGAS','ELCTRANSGAS','ELCMAINSBOM','ELCTRANSBOM') then pv else 0 end ) ^> 0 then >> MainBatchUpload.sql
echo sum(case when fuel in('ELCMAINSBOM','ELCTRANSBOM') then pv else 0 end) / sum(case when fuel in('ELCMAINSGAS','ELCTRANSGAS','ELCMAINSBOM','ELCTRANSBOM') then pv else 0 end ) >> MainBatchUpload.sql
echo else 0 end "biogas" >> MainBatchUpload.sql
echo from cofiring_fuel >> MainBatchUpload.sql
echo group by tablename, period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , elc_waste_heat_process as ( >> MainBatchUpload.sql
echo select tablename, process,userconstraint,attribute,commodity,period,sum(pv) "pv" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where process='EWSTHEAT-OFF-01' and commodity='ELCGEN' and attribute='VAR_FIn' >> MainBatchUpload.sql
echo group by tablename, process,userconstraint,attribute,commodity, period >> MainBatchUpload.sql
echo order by tablename, process,userconstraint,attribute,commodity, period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , elc_waste_heat_available as ( >> MainBatchUpload.sql
echo select tablename,attribute,commodity,process,period, sum(pv) "pv" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where commodity='ELCWSTHEAT' and attribute in ('VAR_FIn','VAR_FOut') >> MainBatchUpload.sql
echo group by tablename,attribute,commodity,process,period >> MainBatchUpload.sql
echo order by tablename,attribute,commodity,process,period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , waste_heat_type as( >> MainBatchUpload.sql
echo select tablename, period, >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Biomass' then pv else 0 end) "Biomass", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Biomass CCS' then pv else 0 end) "Biomass CCS", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Hydrogen' then pv else 0 end) "Hydrogen", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Nuclear' then pv else 0 end) "Nuclear", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Coal' then pv else 0 end) "Coal", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Coal CCS' then pv else 0 end) "Coal CCS", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Coal RR' then pv else 0 end) "Coal RR", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Natural Gas' then pv else 0 end) "Natural Gas", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Natural Gas CCS' then pv else 0 end) "Natural Gas CCS", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Natural Gas RR' then pv else 0 end) "Natural Gas RR", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='Oil' then pv else 0 end) "Oil", >> MainBatchUpload.sql
echo sum(case when "waste_heat"='OIL CCS' then pv else 0 end) "OIL CCS" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename,attribute,period,pv, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('ESTWWST00','EPOLWST00','EBIOS00','EBOG-LFE00','EBOG-SWE00','EMSW00','EBIOCON00','ESTWWST01','EBIO01','EBOG-ADE01','EBOG-LFE01','EBOG-SWE01','EMSW01') then 'Biomass' >> MainBatchUpload.sql
echo when process in('EBIOQ01') then 'Biomass CCS' >> MainBatchUpload.sql
echo when process in('EHYGCCT01') then 'Hydrogen' >> MainBatchUpload.sql
echo when process in('ENUCPWR00','ENUCPWR101','ENUCPWR102') then 'Nuclear' >> MainBatchUpload.sql
echo end "waste_heat" >> MainBatchUpload.sql
echo from elc_waste_heat_available >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select tablename,attribute,period,pv, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('ECOA00','ECOABIO00') then 'Coal' >> MainBatchUpload.sql
echo when process in('ECOAQ01','ECOAQDEMO01') then 'Coal CCS' >> MainBatchUpload.sql
echo when process in('ECOARR01') then 'Coal RR' >> MainBatchUpload.sql
echo when process in('ENGACCT00','ENGAOCT00','ENGAOCT01','ENGARCPE00','ENGARCPE01') then 'Natural Gas' >> MainBatchUpload.sql
echo when process in('ENGACCTQ01','ENGACCTQDEMO01','ENGAQR01') then 'Natural Gas CCS' >> MainBatchUpload.sql
echo when process in('ENGACCTRR01') then 'Natural Gas RR' >> MainBatchUpload.sql
echo when process in('EDSTRCPE00','EDSTRCPE01','EOILL00','EOILS00','EOILS01','EOILL01','EHFOIGCC01') then 'Oil' >> MainBatchUpload.sql
echo when process in('EHFOIGCCQ01') then 'OIL CCS' >> MainBatchUpload.sql
echo end "waste_heat" >> MainBatchUpload.sql
echo from elc_waste_heat_available >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where "waste_heat" is not null >> MainBatchUpload.sql
echo group by tablename, period >> MainBatchUpload.sql
echo order by tablename, period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , retrofit_plants as( >> MainBatchUpload.sql
echo select a.tablename, a.period, >> MainBatchUpload.sql
echo sum(a."coal_rr"*b."Coal RR") "coal_rr", >> MainBatchUpload.sql
echo sum(a."gas_rr"*b."Natural Gas RR") "gas_rr", >> MainBatchUpload.sql
echo sum(a."coalccs_rr"*b."Coal RR") "coalccs_rr", >> MainBatchUpload.sql
echo sum(a."gasccs_rr"*b."Natural Gas RR") "gasccs_rr" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select tablename, period, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when sum(case when proc_set in('ELC FROM COAL RR','ELC FROM COAL CCSRET') then pv else 0 end) ^> 0 then >> MainBatchUpload.sql
echo (sum(case when proc_set='ELC FROM COAL RR' then pv else 0 end)/sum(case when proc_set in('ELC FROM COAL RR','ELC FROM COAL CCSRET') then pv else 0 end)) >> MainBatchUpload.sql
echo else 0 end "coal_rr", >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when sum(case when proc_set in('ELC FROM GAS RR','ELC FROM GAS CCSRET') then pv else 0 end) ^> 0 then >> MainBatchUpload.sql
echo (sum(case when proc_set='ELC FROM GAS RR' then pv else 0 end)/sum(case when proc_set in('ELC FROM GAS RR','ELC FROM GAS CCSRET') then pv else 0 end)) >> MainBatchUpload.sql
echo else 0 end "gas_rr", >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when sum(case when proc_set in('ELC FROM COAL RR','ELC FROM COAL CCSRET') then pv else 0 end) ^> 0 then >> MainBatchUpload.sql
echo (sum(case when proc_set='ELC FROM COAL CCSRET' then pv else 0 end)/sum(case when proc_set in('ELC FROM COAL RR','ELC FROM COAL CCSRET') then pv else 0 end)) >> MainBatchUpload.sql
echo else 0 end "coalccs_rr", >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when sum(case when proc_set in('ELC FROM GAS RR','ELC FROM GAS CCSRET') then pv else 0 end) ^> 0 then >> MainBatchUpload.sql
echo (sum(case when proc_set='ELC FROM GAS CCSRET' then pv else 0 end)/sum(case when proc_set in('ELC FROM GAS RR','ELC FROM GAS CCSRET') then pv else 0 end)) >> MainBatchUpload.sql
echo else 0 end "gasccs_rr" >> MainBatchUpload.sql
echo from elc_prd_fuel >> MainBatchUpload.sql
echo group by tablename, period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo inner join waste_heat_type b >> MainBatchUpload.sql
echo on a.tablename=b.tablename and a.period=b.period >> MainBatchUpload.sql
echo group by a.tablename, a.period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , fuel_shares_to_groups as( >> MainBatchUpload.sql
echo select tablename, period, >> MainBatchUpload.sql
echo "coal_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "coal_grp", >> MainBatchUpload.sql
echo "coalccs_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "coalccs_grp", >> MainBatchUpload.sql
echo "gas_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "gas_grp", >> MainBatchUpload.sql
echo "gasccs_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "gasccs_grp", >> MainBatchUpload.sql
echo "oil_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "oil_grp", >> MainBatchUpload.sql
echo "oilccs_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "oilccs_grp", >> MainBatchUpload.sql
echo "bio_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "bio_grp", >> MainBatchUpload.sql
echo "bioccs_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "bioccs_grp", >> MainBatchUpload.sql
echo "nuclear_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "nuclear_grp", >> MainBatchUpload.sql
echo "h2_grp"/("coal_grp"+"coalccs_grp"+"gas_grp"+"gasccs_grp"+"oil_grp"+"oilccs_grp"+"bio_grp"+"bioccs_grp"+"nuclear_grp"+"h2_grp") "h2_grp" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select a.tablename, a.period, >> MainBatchUpload.sql
echo (sum(c."Coal")+sum("coal_rr"))*sum(a.coal) "coal_grp", >> MainBatchUpload.sql
echo (sum(c."Coal CCS")+sum("coalccs_rr"))*sum(a.coal) "coalccs_grp", >> MainBatchUpload.sql
echo (sum(c."Natural Gas")+sum("gas_rr"))*sum(a.gas) "gas_grp", >> MainBatchUpload.sql
echo (sum(c."Natural Gas CCS")+sum("gasccs_rr"))*sum(a.gas) "gasccs_grp", >> MainBatchUpload.sql
echo (sum(c."Coal")+sum("coal_rr"))*sum(a.oilcoal) + sum(c."Oil")*sum(a.oil) "oil_grp", >> MainBatchUpload.sql
echo sum(c."OIL CCS")*sum(a.oil) + (sum(c."Coal CCS")+sum("coalccs_rr"))*sum(a.oilcoal) "oilccs_grp", >> MainBatchUpload.sql
echo sum(c."Biomass") + (sum(c."Coal")+sum("coal_rr"))*sum(a.biocoal) + >> MainBatchUpload.sql
echo (sum("Natural Gas")+sum("gas_rr"))*sum(a.biogas) + sum(c."Oil")*sum(a.biooil) "bio_grp", >> MainBatchUpload.sql
echo sum(c."Biomass CCS") + (sum(c."Coal CCS")+sum("coalccs_rr"))*sum(a.biocoal) + >> MainBatchUpload.sql
echo (sum(c."Natural Gas CCS")+sum("gasccs_rr"))*sum(a.biogas) + sum(c."OIL CCS")*sum(a.biooil) "bioccs_grp", >> MainBatchUpload.sql
echo sum(c."Nuclear") "nuclear_grp", >> MainBatchUpload.sql
echo sum(c."Hydrogen") "h2_grp" >> MainBatchUpload.sql
echo from cofiring_fuel_percents a full outer join retrofit_plants b >> MainBatchUpload.sql
echo on a.tablename=b.tablename and a.period=b.period >> MainBatchUpload.sql
echo full outer join waste_heat_type c >> MainBatchUpload.sql
echo on a.tablename=c.tablename and a.period=c.period >> MainBatchUpload.sql
echo group by a.tablename, a.period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo , elec_penalty as ( >> MainBatchUpload.sql
echo select a.tablename, a.period, >> MainBatchUpload.sql
echo case when coal_grp*b."ELCGEN" is null then 0 else coal_grp*b."ELCGEN" end "coal", >> MainBatchUpload.sql
echo case when coalccs_grp*b."ELCGEN" is null then 0 else coalccs_grp*b."ELCGEN" end "coalccs", >> MainBatchUpload.sql
echo case when gas_grp*b."ELCGEN" is null then 0 else gas_grp*b."ELCGEN" end "gas", >> MainBatchUpload.sql
echo case when gasccs_grp*b."ELCGEN" is null then 0 else gasccs_grp*b."ELCGEN" end "gasccs", >> MainBatchUpload.sql
echo case when oil_grp*b."ELCGEN" is null then 0 else oil_grp*b."ELCGEN" end "oil", >> MainBatchUpload.sql
echo case when oilccs_grp*b."ELCGEN" is null then 0 else oilccs_grp*b."ELCGEN" end "oilccs", >> MainBatchUpload.sql
echo case when bio_grp*b."ELCGEN" is null then 0 else bio_grp*b."ELCGEN" end "bio", >> MainBatchUpload.sql
echo case when bioccs_grp*b."ELCGEN" is null then 0 else bioccs_grp*b."ELCGEN" end "bioccs", >> MainBatchUpload.sql
echo case when nuclear_grp*b."ELCGEN" is null then 0 else nuclear_grp*b."ELCGEN" end "nuclear", >> MainBatchUpload.sql
echo case when h2_grp*b."ELCGEN" is null then 0 else h2_grp*b."ELCGEN" end "h2" >> MainBatchUpload.sql
echo from fuel_shares_to_groups a >> MainBatchUpload.sql
echo left join ( >> MainBatchUpload.sql
echo select tablename, period, >> MainBatchUpload.sql
echo sum(pv) "ELCGEN" >> MainBatchUpload.sql
echo from elc_waste_heat_process >> MainBatchUpload.sql
echo group by tablename, period >> MainBatchUpload.sql
echo ) b >> MainBatchUpload.sql
echo on a.tablename=b.tablename and a.period=b.period >> MainBatchUpload.sql
echo order by period >> MainBatchUpload.sql
echo ) >> MainBatchUpload.sql
echo select cols ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when cols='elec-gen_intercon' then 'various'::varchar >> MainBatchUpload.sql
echo when cols='elec-gen_waste-heat-penalty' then 'VAR_FIn'::varchar >> MainBatchUpload.sql
echo else 'VAR_FOut'::varchar >> MainBatchUpload.sql
echo end ^|^| '^|various^|various'::varchar "id", >> MainBatchUpload.sql
echo cols::varchar "analysis", >> MainBatchUpload.sql
echo tablename, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when cols='elec-gen_intercon' then 'various'::varchar >> MainBatchUpload.sql
echo when cols='elec-gen_waste-heat-penalty' then 'VAR_FIn'::varchar >> MainBatchUpload.sql
echo else 'VAR_FOut'::varchar >> MainBatchUpload.sql
echo end "attribute", >> MainBatchUpload.sql
echo 'various'::varchar "commodity", >> MainBatchUpload.sql
echo 'various'::varchar "process", >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when cols='elec-gen_inten' then avg(vals) >> MainBatchUpload.sql
echo else sum(vals) >> MainBatchUpload.sql
echo end "all", >> MainBatchUpload.sql
echo sum(case when d.period='2010' then vals else 0 end) as "2010" , >> MainBatchUpload.sql
echo sum(case when d.period='2011' then vals else 0 end) as "2011", >> MainBatchUpload.sql
echo sum(case when d.period='2012' then vals else 0 end) as "2012", >> MainBatchUpload.sql
echo sum(case when d.period='2015' then vals else 0 end) as "2015", >> MainBatchUpload.sql
echo sum(case when d.period='2020' then vals else 0 end) as "2020", >> MainBatchUpload.sql
echo sum(case when d.period='2025' then vals else 0 end) as "2025", >> MainBatchUpload.sql
echo sum(case when d.period='2030' then vals else 0 end) as "2030", >> MainBatchUpload.sql
echo sum(case when d.period='2035' then vals else 0 end) as "2035", >> MainBatchUpload.sql
echo sum(case when d.period='2040' then vals else 0 end) as "2040", >> MainBatchUpload.sql
echo sum(case when d.period='2045' then vals else 0 end) as "2045", >> MainBatchUpload.sql
echo sum(case when d.period='2050' then vals else 0 end) as "2050", >> MainBatchUpload.sql
echo sum(case when d.period='2055' then vals else 0 end) as "2055", >> MainBatchUpload.sql
echo sum(case when d.period='2060' then vals else 0 end) as "2060" >> MainBatchUpload.sql
echo from( >> MainBatchUpload.sql
echo SELECT unnest(array['elec-gen_coal','elec-gen_coal-ccs','elec-gen_nga','elec-gen_nga-ccs','elec-gen_other-ff','elec-gen_bio' >> MainBatchUpload.sql
echo ,'elec-gen_bio-ccs','elec-gen_other-rens','elec-gen_solar','elec-gen_nuclear','elec-gen_offw','elec-gen_onw','elec-gen_chp','elec-gen_total-cen' >> MainBatchUpload.sql
echo ,'elec-gen_intercon','elec-gen_waste-heat-penalty','elec-gen_inten']) AS "cols", >> MainBatchUpload.sql
echo tablename,period, >> MainBatchUpload.sql
echo unnest(array["elec-gen_coal","elec-gen_coal-ccs","elec-gen_nga","elec-gen_nga-ccs","elec-gen_other-ff","elec-gen_bio","elec-gen_bio-ccs" >> MainBatchUpload.sql
echo ,"elec-gen_other-rens","elec-gen_solar","elec-gen_nuclear","elec-gen_offw","elec-gen_onw","elec-gen_chp","elec-gen_total-cen","elec-gen_intercon", >> MainBatchUpload.sql
echo "elec-gen_waste-heat-penalty","elec-gen_inten"]) AS "vals" >> MainBatchUpload.sql
echo FROM ( >> MainBatchUpload.sql
echo select a.tablename,a.period, "coal-unad"*b.coal-d.coal "elec-gen_coal", >> MainBatchUpload.sql
echo "coalccs-unad"*b.coal-d.coalccs "elec-gen_coal-ccs", >> MainBatchUpload.sql
echo "gas-unad"*b.gas-d.gas "elec-gen_nga", >> MainBatchUpload.sql
echo "gasccs-unad"*b.gas-d.gasccs "elec-gen_nga-ccs", >> MainBatchUpload.sql
echo ("ELC FROM OIL"*b.oil+"coal-unad"*b.oilcoal)-d.oil >> MainBatchUpload.sql
echo +("ELC FROM OIL CCS"*b.oil+"coalccs-unad"*b.oilcoal)-d.oilccs >> MainBatchUpload.sql
echo +"ELC FROM MANFUELS" >> MainBatchUpload.sql
echo "elec-gen_other-ff", >> MainBatchUpload.sql
echo ("ELC FROM BIO"+"coal-unad"*biocoal+"ELC FROM OIL"*biooil+"gas-unad"*b.biogas)-d.bio "elec-gen_bio", >> MainBatchUpload.sql
echo ("ELC FROM BIO CCS"+"coalccs-unad"*biocoal+"ELC FROM OIL CCS"*biooil+"gasccs-unad"*b.biogas)-d.bioccs "elec-gen_bio-ccs", >> MainBatchUpload.sql
echo "elec-gen_other-rens"-d.h2 "elec-gen_other-rens", >> MainBatchUpload.sql
echo "elec-gen_solar", >> MainBatchUpload.sql
echo "elec-gen_nuclear"-d.nuclear "elec-gen_nuclear", >> MainBatchUpload.sql
echo "elec-gen_offw", >> MainBatchUpload.sql
echo "elec-gen_onw", >> MainBatchUpload.sql
echo "elec-gen_chp", >> MainBatchUpload.sql
echo "coal-unad"*b.coal-d.coal+"coalccs-unad"*b.coal-d.coalccs+"gas-unad"*b.gas-d.gas+"gasccs-unad"*b.gas-d.gasccs+("ELC FROM OIL"*b.oil+"coal-unad"*b.oilcoal)-d.oil+ >> MainBatchUpload.sql
echo ("ELC FROM OIL CCS"*b.oil+"coalccs-unad"*b.oilcoal)-d.oilccs+"ELC FROM MANFUELS"+("ELC FROM BIO"+"coal-unad"*b.biocoal+"ELC FROM OIL"*b.biooil+ >> MainBatchUpload.sql
echo "gas-unad"*b.biogas)-d.bio+("ELC FROM BIO CCS"+"coalccs-unad"*b.biocoal+"ELC FROM OIL CCS"*b.biooil+ >> MainBatchUpload.sql
echo "gasccs-unad"*b.biogas)-d.bioccs+"elec-gen_other-rens"-d.h2+"elec-gen_solar"+"elec-gen_nuclear"-d.nuclear+"elec-gen_offw"+"elec-gen_onw"+"elec-gen_chp" "elec-gen_total-cen", >> MainBatchUpload.sql
echo "elec-gen_intercon", >> MainBatchUpload.sql
echo "elec-gen_waste-heat-penalty", >> MainBatchUpload.sql
echo "elc-emis"/ >> MainBatchUpload.sql
echo ("coal-unad"*b.coal+"coalccs-unad"*b.coal+"gas-unad"*b.gas+"gasccs-unad"*b.gas+"ELC FROM OIL"*b.oil+"coal-unad"*b.oilcoal+"ELC FROM OIL CCS"*b.oil+"coalccs-unad"*b.oilcoal+ >> MainBatchUpload.sql
echo "ELC FROM MANFUELS"+"ELC FROM BIO"+"coal-unad"*b.biocoal+"ELC FROM OIL"*b.biooil+"gas-unad"*b.biogas+"ELC FROM BIO CCS"+"coalccs-unad"*b.biocoal+"ELC FROM OIL CCS"*b.biooil+ >> MainBatchUpload.sql
echo "gasccs-unad"*b.biogas+"elec-gen_other-rens"+"elec-gen_solar"+"elec-gen_nuclear"+"elec-gen_offw"+"elec-gen_onw"+"elec-gen_chp"-"elec-gen_waste-heat-penalty" >> MainBatchUpload.sql
echo -(case when "elec-gen_intercon"^<0 then "elec-gen_intercon" else 0 end))*3600 >> MainBatchUpload.sql
echo "elec-gen_inten" >> MainBatchUpload.sql
echo from( >> MainBatchUpload.sql
echo select a.period, a.tablename, >> MainBatchUpload.sql
echo sum(case when proc_set='ELC TO EXPORTS' then -pv when proc_set='ELC FROM IMPORTS' then pv else 0 end) "elec-gen_intercon", >> MainBatchUpload.sql
echo sum(case when proc_set in ('ELC FROM TIDAL','ELC FROM WAVE','ELC FROM GEO','ELC FROM HYDRO','ELC FROM HYDROGEN') then pv else 0 end) "elec-gen_other-rens", >> MainBatchUpload.sql
echo sum(case when proc_set in ('ELC FROM SOL-PV') then pv else 0 end) "elec-gen_solar", >> MainBatchUpload.sql
echo sum(case when proc_set in ('ELC FROM NUCLEAR') then pv else 0 end) "elec-gen_nuclear", >> MainBatchUpload.sql
echo sum(case when proc_set in ('ELC FROM WIND-OFFSH') then pv else 0 end) "elec-gen_offw", >> MainBatchUpload.sql
echo sum(case when proc_set in ('ELC FROM WIND-ONSH') then pv else 0 end) "elec-gen_onw", >> MainBatchUpload.sql
echo sum(case when proc_set in ('elec-gen_chp') then pv else 0 end) "elec-gen_chp", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM COAL-COF' then pv else 0 end)+sum(case when proc_set='ELC FROM COAL RR' then pv else 0 end) "coal-unad", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM COALCOF CCS' then pv else 0 end)+sum(case when proc_set='ELC FROM COAL CCSRET' then pv else 0 end) "coalccs-unad", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM GAS' then pv else 0 end)+sum(case when proc_set='ELC FROM GAS RR' then pv else 0 end) "gas-unad", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM GAS CCS' then pv else 0 end)+sum(case when proc_set='ELC FROM GAS CCSRET' then pv else 0 end) "gasccs-unad", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM OIL' then pv else 0 end) "ELC FROM OIL", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM OIL CCS' then pv else 0 end) "ELC FROM OIL CCS", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM MANFUELS' then pv else 0 end) "ELC FROM MANFUELS", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM BIO' then pv else 0 end) "ELC FROM BIO", >> MainBatchUpload.sql
echo sum(case when proc_set='ELC FROM BIO CCS' then pv else 0 end) "ELC FROM BIO CCS", >> MainBatchUpload.sql
echo sum(case when proc_set='elec-gen_waste-heat-penalty' then pv else 0 end) "elec-gen_waste-heat-penalty" >> MainBatchUpload.sql
echo from elc_prd_fuel a >> MainBatchUpload.sql
echo group by a.tablename, a.period >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo left join cofiring_fuel_percents b >> MainBatchUpload.sql
echo on a.tablename=b.tablename and a.period=b.period >> MainBatchUpload.sql
echo left join "elc-emis" c >> MainBatchUpload.sql
echo on a.tablename=c.tablename and a.period=c.period >> MainBatchUpload.sql
echo left join "elec_penalty" d >> MainBatchUpload.sql
echo on a.tablename=d.tablename and a.period=d.period >> MainBatchUpload.sql
echo ) c >> MainBatchUpload.sql
echo ) d >> MainBatchUpload.sql
echo group by tablename,cols >> MainBatchUpload.sql
echo ORDER BY tablename,analysis >> MainBatchUpload.sql
echo ) TO '%~dp0ElecGenOut.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *Electricity storage by type* */echo /* *Electricity storage by type* */ >> MainBatchUpload.sql
echo copy ( >> MainBatchUpload.sql
echo select analysis ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| attribute ^|^| '^|' ^|^| '-^|various'::varchar(300) "id", >> MainBatchUpload.sql
echo analysis::varchar(50), tablename,attribute,commodity,'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select process,period,pv, >> MainBatchUpload.sql
echo 'elec-stor-out_' ^|^| >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('EHYDPMP00','EHYDPMP01') then 'hyd' >> MainBatchUpload.sql
echo when process in ('ECAESCON01','ESTGCAES01','ECAESTUR01','ESTGAACAES01') then 'caes' >> MainBatchUpload.sql
echo when process in ('ESTGBNAS01','ESTGBALA01','ESTGBRF01') then 'batt' >> MainBatchUpload.sql
echo end as "analysis", tablename, attribute,commodity >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute = 'VAR_FOut' and commodity='ELC' >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where analysis is not null >> MainBatchUpload.sql
echo group by id,analysis,tablename,attribute,commodity >> MainBatchUpload.sql
echo order by tablename, analysis >> MainBatchUpload.sql
echo ) to '%~dp0ElecStor.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *Electricity capacity by process* */echo /* *Electricity capacity by process* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select analysis ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| attribute ^|^| '^|' ^|^| '-^|various'::varchar(300) "id", analysis, tablename,attribute, >> MainBatchUpload.sql
echo '-'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select process, >> MainBatchUpload.sql
echo period,pv, >> MainBatchUpload.sql
echo 'elec-cap_' ^|^| >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in('ESTWWST00','EPOLWST00', 'EBIOS00','EBOG-LFE00','EBOG-SWE00', >> MainBatchUpload.sql
echo 'EMSW00','EBIOCON00','ESTWWST01','EBIO01','EBOG-ADE01', >> MainBatchUpload.sql
echo 'EBOG-LFE01','EBOG-SWE01','EMSW01') then 'bio' >> MainBatchUpload.sql
echo when process = 'EBIOQ01' then 'bio-ccs' >> MainBatchUpload.sql
echo when process in('ECOA00','ECOABIO00', 'ECOARR01') then 'coal' >> MainBatchUpload.sql
echo when process in('ECOAQ01' ,'ECOAQDEMO01','ECOAQR01') then 'coal-ccs' >> MainBatchUpload.sql
echo when process in('EHYGCCT01' ,'EHYGOCT01') then 'h2' >> MainBatchUpload.sql
echo when process in('ENGACCT00','ENGACCTRR01','ENGAOCT00','ENGAOCT01','ENGARCPE00','ENGARCPE01') then >> MainBatchUpload.sql
echo 'nga' >> MainBatchUpload.sql
echo when process in('ENGACCTQ01','ENGACCTQDEMO01','ENGAQR01') then 'nga-ccs' >> MainBatchUpload.sql
echo when process in('ENUCPWR00','ENUCPWR101','ENUCPWR102') then >> MainBatchUpload.sql
echo 'nuclear' >> MainBatchUpload.sql
echo when process in('EWNDOFF00','EWNDOFF101','EWNDOFF201') then 'offw' >> MainBatchUpload.sql
echo when process in('EWNDONS00','EWNDONS101','EWNDONS201') then 'onw' >> MainBatchUpload.sql
echo when process ='EHFOIGCCQ01' then 'other-ccs' >> MainBatchUpload.sql
echo when process in('EOILL00','EOILL01','EMANOCT00','EMANOCT01','EOILS00','EOILS01','EHFOIGCC01','EDSTRCPE00','EDSTRCPE01') then >> MainBatchUpload.sql
echo 'other-ff' >> MainBatchUpload.sql
echo when process in('EHYD00','EHYD01','EGEO01','ETIR101','ETIB101','ETIS101','EWAV101') then >> MainBatchUpload.sql
echo 'other-rens' >> MainBatchUpload.sql
echo when process in('ESOL00','ESOLPV00','ESOL01','ESOLPV01') then 'solar' >> MainBatchUpload.sql
echo when process in('ICHCHPBIOG01','ICHCHPBIOS00','ICHCHPBIOS01', >> MainBatchUpload.sql
echo 'ICHCHPCCGT01','ICHCHPCCGTH01','ICHCHPCOA00','ICHCHPCOA01', >> MainBatchUpload.sql
echo 'ICHCHPFCH01','ICHCHPGT01','ICHCHPHFO00','ICHCHPLFO00', >> MainBatchUpload.sql
echo 'ICHCHPLPG00','ICHCHPLPG01','ICHCHPNGA00','ICHCHPPRO00', >> MainBatchUpload.sql
echo 'ICHCHPPRO01','IFDCHPBIOG01','IFDCHPBIOS00','IFDCHPBIOS01', >> MainBatchUpload.sql
echo 'IFDCHPCCGT01','IFDCHPCCGTH01','IFDCHPCOA00','IFDCHPCOA01', >> MainBatchUpload.sql
echo 'IFDCHPFCH01','IFDCHPGT01','IFDCHPHFO00','IFDCHPLFO00', >> MainBatchUpload.sql
echo 'IFDCHPNGA00','IISCHPBFG00','IISCHPBFG01','IISCHPBIOG01', >> MainBatchUpload.sql
echo 'IISCHPBIOS01','IISCHPCCGT01','IISCHPCCGTH01','IISCHPCOG00', >> MainBatchUpload.sql
echo 'IISCHPCOG01','IISCHPFCH01','IISCHPGT01','IISCHPHFO00', >> MainBatchUpload.sql
echo 'IISCHPNGA00','INMCHPBIOG01','INMCHPBIOS01','INMCHPCCGT01', >> MainBatchUpload.sql
echo 'INMCHPCCGTH01','INMCHPCOA01','INMCHPCOG00','INMCHPCOG01', >> MainBatchUpload.sql
echo 'INMCHPFCH01','INMCHPGT01','INMCHPNGA00','IOICHPBIOG01', >> MainBatchUpload.sql
echo 'IOICHPBIOS00','IOICHPBIOS01','IOICHPCCGT01','IOICHPCCGTH01', >> MainBatchUpload.sql
echo 'IOICHPCOA01','IOICHPFCH01','IOICHPGT01','IOICHPHFO00', >> MainBatchUpload.sql
echo 'IOICHPNGA00','IPPCHPBIOG01','IPPCHPBIOS00','IPPCHPBIOS01', >> MainBatchUpload.sql
echo 'IPPCHPCCGT01','IPPCHPCCGTH01','IPPCHPCOA00','IPPCHPCOA01', >> MainBatchUpload.sql
echo 'IPPCHPFCH01','IPPCHPGT01','IPPCHPNGA00','IPPCHPWST00', >> MainBatchUpload.sql
echo 'IPPCHPWST01','PCHP-CCP00','PCHP-CCP01','RCHPEA-CCG00', >> MainBatchUpload.sql
echo 'RCHPEA-CCG01','RCHPEA-CCH01','RCHPEA-FCH01','RCHPEA-STW01', >> MainBatchUpload.sql
echo 'RCHPNA-CCG01','RCHPNA-CCH01','RCHPNA-FCH01','RCHPNA-STW01', >> MainBatchUpload.sql
echo 'RHEACHPRG01','RHEACHPRH01','RHEACHPRW01','RHNACHPRG01', >> MainBatchUpload.sql
echo 'RHNACHPRH01','RHNACHPRW01','RCHPEA-EFW01','RCHPNA-EFW01', >> MainBatchUpload.sql
echo 'SCHP-ADM01','SCHP-CCG00','SCHP-CCG01','SCHP-CCH01', >> MainBatchUpload.sql
echo 'SCHP-FCH01','SCHP-GES00','SCHP-GES01','SCHP-STM01', >> MainBatchUpload.sql
echo 'SCHP-STW00','SCHP-STW01','SHLCHPRG01','SHLCHPRH01', >> MainBatchUpload.sql
echo 'SHLCHPRW01','SCHP-EFW01','UCHP-CCG00','UCHP-CCG01', >> MainBatchUpload.sql
echo 'RHFCCHPRH01','RHFSCHPRH01','RHHCCHPRH01','RHHSCHPRH01', >> MainBatchUpload.sql
echo 'RHFCCHPRG01','RHFSCHPRG01','RHHCCHPRG01','RHHSCHPRG01', >> MainBatchUpload.sql
echo 'RHFCCHPRW01','RHFSCHPRW01','RHHCCHPRW01','RHHSCHPRW01') then 'chp' >> MainBatchUpload.sql
echo when process in('ELCIE00','ELCII00','ELCIE01','ELCII01') then 'intercon' >> MainBatchUpload.sql
echo when process in('EHYDPMP00','EHYDPMP01') then 'hyd' >> MainBatchUpload.sql
echo when process in ('ECAESCON01','ESTGCAES01','ECAESTUR01','ESTGAACAES01') then 'caes' >> MainBatchUpload.sql
echo when process in ('ESTGBNAS01','ESTGBALA01','ESTGBRF01') then 'batt' >> MainBatchUpload.sql
echo end::varchar(50) as "analysis", >> MainBatchUpload.sql
echo tablename, attribute >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute = 'VAR_Cap' and commodity = '-' >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo where analysis is not null >> MainBatchUpload.sql
echo group by id, analysis,tablename, attribute >> MainBatchUpload.sql
echo order by tablename, analysis, attribute, commodity >> MainBatchUpload.sql
echo ) TO '%~dp0ElecCap.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *costs by sector and type* */echo /* *costs by sector and type* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select analysis ^|^| '^|' ^|^| tablename ^|^|'^|'^|^| attribute ^|^| '^|various' ^|^| '^|various'::varchar(300) "id", analysis, tablename,attribute, >> MainBatchUpload.sql
echo 'various'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "various", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select process, >> MainBatchUpload.sql
echo period,pv, >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process like 'T%%' then 'costs_tra' >> MainBatchUpload.sql
echo when process like 'A%%' then 'costs_agr' >> MainBatchUpload.sql
echo when process like 'E%%' AND process not like 'EXP%%' then 'costs_elc' >> MainBatchUpload.sql
echo when process like 'I%%' AND process not like 'IMP%%' then 'costs_ind' >> MainBatchUpload.sql
echo when process like 'P%%' or process like 'C%%' then 'costs_prc' >> MainBatchUpload.sql
echo when process like 'R%%' then 'costs_res' >> MainBatchUpload.sql
echo when process like any(array['M%%','U%%','IMP%%','EXP%%']) then 'costs_rsr' >> MainBatchUpload.sql
echo when process like 'S%%' then 'costs_ser' >> MainBatchUpload.sql
echo else 'costs_other' >> MainBatchUpload.sql
echo end::varchar(50) as "analysis",tablename, attribute >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute in('Cost_Act', 'Cost_Flo', 'Cost_Fom', 'Cost_Inv', 'Cost_Salv') >> MainBatchUpload.sql
echo union all >> MainBatchUpload.sql
echo select 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo period,pv, >> MainBatchUpload.sql
echo 'costs_all'::varchar(50) "analysis", >> MainBatchUpload.sql
echo tablename, >> MainBatchUpload.sql
echo attribute >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute in('Cost_Act','Cost_Flo','Cost_Fom','Cost_Inv','Cost_Salv','ObjZ') >> MainBatchUpload.sql
echo ) a >> MainBatchUpload.sql
echo group by id, analysis, tablename, attribute >> MainBatchUpload.sql
echo order by tablename, analysis, attribute >> MainBatchUpload.sql
echo ) TO '%~dp0CostsBySec.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *Marginal prices for emissions* */echo /* *Marginal prices for emissions* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select 'marg-price^|' ^|^| tablename ^|^| '^|EQ_CombalM^|' ^|^| commodity ^|^| '^|-'::varchar(300) "id", >> MainBatchUpload.sql
echo 'marg-price'::varchar(50) "analysis", >> MainBatchUpload.sql
echo tablename, >> MainBatchUpload.sql
echo 'EQ_CombalM'::varchar(50) "attribute", >> MainBatchUpload.sql
echo commodity, >> MainBatchUpload.sql
echo '-'::varchar(50) "process", >> MainBatchUpload.sql
echo NULL::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from vedastore >> MainBatchUpload.sql
echo where attribute='EQ_CombalM' and commodity in('GHG-NO-IAS-YES-LULUCF-NET','GHG-NO-AS-YES-LULUCF-NET', >> MainBatchUpload.sql
echo 'GHG-ETS-NO-IAS-NET','GHG-YES-IAS-YES-LULUCF-NET','GHG-ETS-YES-IAS-NET') >> MainBatchUpload.sql
echo group by tablename, commodity >> MainBatchUpload.sql
echo order by tablename, commodity >> MainBatchUpload.sql
echo ) TO '%~dp0MarginalPricesOut.csv' delimiter ',' CSV; >> MainBatchUpload.sql
rem /* *Whole stock heat output by process for residential* */echo /* *Whole stock heat output by process for residential* */ >> MainBatchUpload.sql
echo COPY ( >> MainBatchUpload.sql
echo select analysis ^|^| '^|' ^|^| tablename ^|^| '^|' ^|^| attribute ^|^| '^|' ^|^| 'various^|various'::varchar(300) "id", analysis::varchar(50), tablename,attribute, >> MainBatchUpload.sql
echo 'various'::varchar(50) "commodity", >> MainBatchUpload.sql
echo 'various'::varchar(50) "process", >> MainBatchUpload.sql
echo sum(pv)::numeric "all", >> MainBatchUpload.sql
echo sum(case when period='2010' then pv else 0 end)::numeric "2010", >> MainBatchUpload.sql
echo sum(case when period='2011' then pv else 0 end)::numeric "2011", >> MainBatchUpload.sql
echo sum(case when period='2012' then pv else 0 end)::numeric "2012", >> MainBatchUpload.sql
echo sum(case when period='2015' then pv else 0 end)::numeric "2015", >> MainBatchUpload.sql
echo sum(case when period='2020' then pv else 0 end)::numeric "2020", >> MainBatchUpload.sql
echo sum(case when period='2025' then pv else 0 end)::numeric "2025", >> MainBatchUpload.sql
echo sum(case when period='2030' then pv else 0 end)::numeric "2030", >> MainBatchUpload.sql
echo sum(case when period='2035' then pv else 0 end)::numeric "2035", >> MainBatchUpload.sql
echo sum(case when period='2040' then pv else 0 end)::numeric "2040", >> MainBatchUpload.sql
echo sum(case when period='2045' then pv else 0 end)::numeric "2045", >> MainBatchUpload.sql
echo sum(case when period='2050' then pv else 0 end)::numeric "2050", >> MainBatchUpload.sql
echo sum(case when period='2055' then pv else 0 end)::numeric "2055", >> MainBatchUpload.sql
echo sum(case when period='2060' then pv else 0 end)::numeric "2060" >> MainBatchUpload.sql
echo from ( >> MainBatchUpload.sql
echo select process, >> MainBatchUpload.sql
echo period,pv, >> MainBatchUpload.sql
echo 'heat-res_' ^|^| >> MainBatchUpload.sql
echo case >> MainBatchUpload.sql
echo when process in ('RHEABLCRP01','RHEABLRRW00','RHEABLRRW01','RHEABLSRP01','RHEABLSRW01', >> MainBatchUpload.sql
echo 'RHNABLCRP01','RHNABLRRW01','RHNABLSRP01','RHNABLSRW01') then 'boiler-bio' >> MainBatchUpload.sql
echo when process in('RHEABLCRH01','RHEABLSRH01','RHNABLCRH01','RHNABLSRH01') then 'boiler-h2' >> MainBatchUpload.sql
echo when process in('RHEABLCRO00','RHEABLCRO01','RHEABLRRC00','RHEABLRRO00','RHEABLSRO01','RHNABLCRO01' >> MainBatchUpload.sql
echo ,'RHNABLSRO01') then 'boiler-otherFF' >> MainBatchUpload.sql
echo when process in('RHEABLRRE00','RHEABLRRE01','RHEABLSRE01','RHEASHTRE00', >> MainBatchUpload.sql
echo 'RHEASHTRE01','RHNABLRRE01','RHNABLSRE01','RHNAGHPUE01','RHNASHTRE01', >> MainBatchUpload.sql
echo 'RWEAWHTRE00','RWEAWHTRE01','RWNAWHTRE01') then 'boiler/heater-elec' >> MainBatchUpload.sql
echo when process in('RHEABLCRG00','RHEABLCRG01', >> MainBatchUpload.sql
echo 'RHEABLRRG00','RHEABLSRG01','RHEASHTRG00','RHEASHTRG01','RHNABLCRG01', >> MainBatchUpload.sql
echo 'RHNABLSRG01','RHNASHTRG01','RWEAWHTRG00','RWEAWHTRG01','RWNAWHTRG01') then >> MainBatchUpload.sql
echo 'boiler/heater-nga' >> MainBatchUpload.sql
echo when process='RHEACSVCAV01' then 'easy-cav' >> MainBatchUpload.sql
echo when process='RHEACSVCAV02' then 'hard-cav' >> MainBatchUpload.sql
echo when process='RHEACSVSOL01' then 'solid-sysbld' >> MainBatchUpload.sql
echo when process in('RHEACSVLOF01','RHEACSVFLR01', >> MainBatchUpload.sql
echo 'RHEACSVWIN01','RHEACSVFLU01','RHEACSVDFT01','RHEACSVCON01','RHEACSVCYL01') then >> MainBatchUpload.sql
echo 'other-conserv' >> MainBatchUpload.sql
echo when process in('RHEADHP100','RHEADHP101','RHEADHP201','RHEADHP301','RHEADHP401', >> MainBatchUpload.sql
echo 'RHNADHP101','RHNADHP201','RHNADHP301','RHNADHP401') then 'dh' >> MainBatchUpload.sql