/
pghydro--6.6.sql
6232 lines (4369 loc) · 179 KB
/
pghydro--6.6.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
--
-- Copyright (c) 2022 Alexandre de Amorim Teixeira, pghydro.project@gmail.com
--
-- This program is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program; if not, write to the Free Software
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--REQUIREMENTS
--Postgresql version 9+
--PostGIS version 3+
---------------------------------------------------------------------------------
--PgHydro Extension Version 6.6 of 28/07/2022
---------------------------------------------------------------------------------
-------------------------------------
--CREATE SCHEMA, TABLES AND SEQUENCES
-------------------------------------
DROP SCHEMA IF EXISTS pghydro CASCADE;
CREATE SCHEMA pghydro;
--
CREATE TABLE pghydro.pghft_shoreline (
sho_pk integer,
sho_gm_length numeric,
sho_bo_flowdirection boolean,
sho_nm character varying,
sho_gm geometry(MultiLineString)
);
CREATE SEQUENCE pghydro.sho_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.sho_pk_seq OWNED BY pghydro.pghft_shoreline.sho_pk;
SELECT pg_catalog.setval('pghydro.sho_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_domain (
tdm_pk integer,
tdm_ds character varying
);
CREATE SEQUENCE pghydro.tdm_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tdm_pk_seq OWNED BY pghydro.pghtb_type_domain.tdm_pk;
SELECT pg_catalog.setval('pghydro.tdm_pk_seq', 1, false);
CREATE TABLE pghydro.pghft_hydro_intel(
hin_pk integer,
hin_drn_pk integer,
hin_dra_pk integer,
hin_count_drn_pk integer,
hin_count_dra_pk integer,
hin_strahler integer,
hin_gm_point geometry(Point),
hin_gm_line geometry(MultiLineString),
hin_gm_polygon geometry(MultiPolygon)
);
CREATE SEQUENCE pghydro.hin_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.hin_pk_seq OWNED BY pghydro.pghft_hydro_intel.hin_pk;
SELECT pg_catalog.setval('pghydro.hin_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_drainage_point (
drp_pk integer,
drp_nu_valence smallint,
drp_gm geometry(Point)
);
CREATE SEQUENCE pghydro.drp_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.drp_pk_seq OWNED BY pghydro.pghft_drainage_point.drp_pk;
SELECT pg_catalog.setval('pghydro.drp_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_drainage_line (
drn_pk integer,
drn_drp_pk_sourcenode integer,
drn_rcl_pk_drp_sourcenode integer,
drn_drp_pk_targetnode integer,
drn_rcl_pk_drp_targetnode integer,
drn_drn_pk_upstreamdrainageline integer,
drn_drn_pk_downstreamdrainageline integer,
drn_nu_distancetosea numeric,
drn_nu_distancetowatercourse numeric,
drn_bo_flowdirection boolean,
drn_nm character varying,
drn_tnc_pk integer,
drn_gm_length numeric,
drn_dra_pk integer,
drn_rcl_pk_dra integer,
drn_nu_upstreamarea numeric,
drn_wtc_pk integer,
drn_rcl_pk_wtc integer,
drn_tdm_pk integer,
drn_gm_point geometry(Multipoint),
drn_gm geometry(MultiLineString)
);
CREATE SEQUENCE pghydro.drn_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.drn_pk_seq OWNED BY pghydro.pghft_drainage_line.drn_pk;
SELECT pg_catalog.setval('pghydro.drn_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_drainage_area (
dra_pk integer,
dra_cd_pfafstetterbasin character varying,
dra_nu_pfafstetterbasincodelevel smallint,
dra_gm_area numeric,
dra_gm geometry(MultiPolygon)
);
CREATE SEQUENCE pghydro.dra_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.dra_pk_seq OWNED BY pghydro.pghft_drainage_area.dra_pk;
SELECT pg_catalog.setval('pghydro.dra_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_shoreline_ending_point (
sep_pk integer,
sep_drp_pk integer,
sep_rcl_pk_drp integer,
sep_drn_pk integer,
sep_rcl_pk_drn integer,
sep_sho_pk integer,
sep_rcl_pk_sho integer,
sep_gm geometry(Point)
);
CREATE SEQUENCE pghydro.sep_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.sep_pk_seq OWNED BY pghydro.pghft_shoreline_ending_point.sep_pk;
SELECT pg_catalog.setval('pghydro.sep_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_shoreline_starting_point (
ssp_pk integer,
ssp_drp_pk integer,
ssp_rcl_pk_drp integer,
ssp_drn_pk integer,
ssp_rcl_pk_drn integer,
ssp_sho_pk integer,
ssp_rcl_pk_sho integer,
ssp_gm geometry(Point)
);
CREATE SEQUENCE pghydro.ssp_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.ssp_pk_seq OWNED BY pghydro.pghft_shoreline_starting_point.ssp_pk;
SELECT pg_catalog.setval('pghydro.ssp_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_stream_mouth (
stm_pk integer,
stm_drp_pk integer,
stm_rcl_pk_drp integer,
stm_wtc_pk integer,
stm_rcl_pk_wtc integer,
stm_gm geometry(Point)
);
CREATE SEQUENCE pghydro.stm_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.stm_pk_seq OWNED BY pghydro.pghft_stream_mouth.stm_pk;
SELECT pg_catalog.setval('pghydro.stm_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_watercourse (
wtc_pk integer,
wtc_nu_distancetosea numeric,
wtc_cd_pfafstetterwatercourse_downstream character varying,
wtc_cd_pfafstetterwatercourse character varying,
wtc_nu_pfafstetterwatercoursecodelevel smallint,
wtc_nu_pfafstetterwatercoursecodeorder smallint,
wtc_gm_area numeric,
wtc_gm_length numeric,
wtc_tdm_pk integer,
wtc_gm geometry(MultiLineString)
);
CREATE SEQUENCE pghydro.wtc_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.wtc_pk_seq OWNED BY pghydro.pghft_watercourse.wtc_pk;
SELECT pg_catalog.setval('pghydro.wtc_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_watercourse_starting_point (
wsp_pk integer,
wsp_drp_pk integer,
wsp_rcl_pk_drp integer,
wsp_wtc_pk integer,
wsp_rcl_pk_wtc integer,
wsp_gm geometry(Point)
);
CREATE SEQUENCE pghydro.wsp_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.wsp_pk_seq OWNED BY pghydro.pghft_watercourse_starting_point.wsp_pk;
SELECT pg_catalog.setval('pghydro.wsp_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_watercourse_ending_point (
wep_pk integer,
wep_drp_pk integer,
wep_rcl_pk_drp integer,
wep_wtc_pk integer,
wep_rcl_pk_wtc integer,
wep_gm geometry(Point)
);
CREATE SEQUENCE pghydro.wep_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.wep_pk_seq OWNED BY pghydro.pghft_watercourse_ending_point.wep_pk;
SELECT pg_catalog.setval('pghydro.wep_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghft_watershed (
wts_pk integer,
wts_cd_pfafstetterbasin character varying,
wts_cd_pfafstetterbasincodelevel smallint,
wts_gm_area numeric,
wts_gm geometry(MultiPolygon)
);
CREATE SEQUENCE pghydro.wts_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.wts_pk_seq OWNED BY pghydro.pghft_watershed.wts_pk;
SELECT pg_catalog.setval('pghydro.wts_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_de9im (
dim_pk integer,
dim_ds character varying(9)
);
CREATE SEQUENCE pghydro.dim_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.dim_pk_seq OWNED BY pghydro.pghtb_type_de9im.dim_pk;
SELECT pg_catalog.setval('pghydro.dim_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_geometry (
tgm_pk integer,
tgm_ds character varying
);
CREATE SEQUENCE pghydro.tgm_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tgm_pk_seq OWNED BY pghydro.pghtb_type_geometry.tgm_pk;
SELECT pg_catalog.setval('pghydro.tgm_pk_seq', 8, true);
--
CREATE TABLE pghydro.pghtb_type_relationship_class (
rcl_pk integer,
rcl_tgm_pk_class_a integer,
rcl_tgm_ds_class_a character varying,
rcl_tgm_pk_class_b integer,
rcl_tgm_ds_class_b character varying,
rcl_tpr_pk integer,
rcl_tpr_ds character varying,
rcl_dim_pk integer,
rcl_dim_ds character varying
);
CREATE SEQUENCE pghydro.rcl_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.rcl_pk_seq OWNED BY pghydro.pghtb_type_relationship_class.rcl_pk;
SELECT pg_catalog.setval('pghydro.rcl_pk_seq', 14, true);
--
CREATE TABLE pghydro.pghtb_type_topology_relationship (
tpr_pk integer,
tpr_ds character varying
);
CREATE SEQUENCE pghydro.tpr_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tpr_pk_seq OWNED BY pghydro.pghtb_type_topology_relationship.tpr_pk;
SELECT pg_catalog.setval('pghydro.tpr_pk_seq', 5, true);
--
CREATE TABLE pghydro.pghtb_primary_key_columns (
f_table_catalog character varying(256),
f_table_schema character varying(256),
f_table_name character varying(256),
f_primary_key_column character varying(256)
);
--
CREATE TABLE pghydro.pghtb_foreign_key_columns (
f_table_catalog character varying(256),
f_table_schema character varying(256),
f_table_name character varying(256),
f_foreign_key_column character varying(256),
f_table_catalog_reference character varying(256),
f_table_schema_reference character varying(256),
f_table_name_reference character varying(256),
f_primary_key_column_reference character varying(256)
);
--
CREATE TABLE pghydro.pghtb_index_columns (
f_table_catalog character varying(256),
f_table_schema character varying(256),
f_table_name character varying(256),
f_index_column character varying(256),
f_index_column_method character varying(256)
);
CREATE TABLE pghydro.pghtb_type_name_complete (
tnc_pk integer,
tnc_ds character varying,
tnc_tng_pk integer,
tnc_tcn_pk integer,
tnc_tns_pk integer
);
CREATE SEQUENCE pghydro.tnc_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tnc_pk_seq OWNED BY pghydro.pghtb_type_name_complete.tnc_pk;
SELECT pg_catalog.setval('pghydro.tnc_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_name_connection (
tcn_pk integer,
tcn_ds character varying
);
CREATE SEQUENCE pghydro.tcn_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tcn_pk_seq OWNED BY pghydro.pghtb_type_name_connection.tcn_pk;
SELECT pg_catalog.setval('pghydro.tcn_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_name_generic (
tng_pk integer,
tng_ds character varying
);
CREATE SEQUENCE pghydro.tng_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tng_pk_seq OWNED BY pghydro.pghtb_type_name_generic.tng_pk;
SELECT pg_catalog.setval('pghydro.tng_pk_seq', 1, false);
--
CREATE TABLE pghydro.pghtb_type_name_specific (
tns_pk integer,
tns_ds character varying
);
CREATE SEQUENCE pghydro.tns_pk_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
ALTER SEQUENCE pghydro.tns_pk_seq OWNED BY pghydro.pghtb_type_name_specific.tns_pk;
SELECT pg_catalog.setval('pghydro.tns_pk_seq', 1, false);
--
ALTER TABLE pghydro.pghft_shoreline ALTER COLUMN sho_pk SET DEFAULT nextval('pghydro.sho_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_domain ALTER COLUMN tdm_pk SET DEFAULT nextval('pghydro.tdm_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_hydro_intel ALTER COLUMN hin_pk SET DEFAULT nextval('pghydro.hin_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_drainage_point ALTER COLUMN drp_pk SET DEFAULT nextval('pghydro.drp_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_drainage_line ALTER COLUMN drn_pk SET DEFAULT nextval('pghydro.drn_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_drainage_area ALTER COLUMN dra_pk SET DEFAULT nextval('pghydro.dra_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_shoreline_ending_point ALTER COLUMN sep_pk SET DEFAULT nextval('pghydro.sep_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_shoreline_starting_point ALTER COLUMN ssp_pk SET DEFAULT nextval('pghydro.ssp_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_stream_mouth ALTER COLUMN stm_pk SET DEFAULT nextval('pghydro.stm_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_watercourse ALTER COLUMN wtc_pk SET DEFAULT nextval('pghydro.wtc_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_watercourse_starting_point ALTER COLUMN wsp_pk SET DEFAULT nextval('pghydro.wsp_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_watercourse_ending_point ALTER COLUMN wep_pk SET DEFAULT nextval('pghydro.wep_pk_seq'::regclass);
ALTER TABLE pghydro.pghft_watershed ALTER COLUMN wts_pk SET DEFAULT nextval('pghydro.wts_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_de9im ALTER COLUMN dim_pk SET DEFAULT nextval('pghydro.dim_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_geometry ALTER COLUMN tgm_pk SET DEFAULT nextval('pghydro.tgm_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_relationship_class ALTER COLUMN rcl_pk SET DEFAULT nextval('pghydro.rcl_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_topology_relationship ALTER COLUMN tpr_pk SET DEFAULT nextval('pghydro.tpr_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_name_complete ALTER COLUMN tnc_pk SET DEFAULT nextval('pghydro.tnc_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_name_generic ALTER COLUMN tng_pk SET DEFAULT nextval('pghydro.tng_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_name_connection ALTER COLUMN tcn_pk SET DEFAULT nextval('pghydro.tcn_pk_seq'::regclass);
ALTER TABLE pghydro.pghtb_type_name_specific ALTER COLUMN tns_pk SET DEFAULT nextval('pghydro.tns_pk_seq'::regclass);
-----------------------------------------
--UpdateExtension
-----------------------------------------
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_drainage_area', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_drainage_line', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_drainage_point', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_hydro_intel', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_shoreline', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_shoreline_ending_point', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_shoreline_starting_point', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_stream_mouth', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_watercourse', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_watercourse_ending_point', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_watercourse_starting_point', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghft_watershed', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghtb_type_name_complete', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghtb_type_name_connection', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghtb_type_name_generic', '');
SELECT pg_catalog.pg_extension_config_dump('pghydro.pghtb_type_name_specific', '');
-----------------------------
--INSERT DATA
-----------------------------
--
DELETE FROM pghydro.pghtb_type_geometry;
INSERT INTO pghydro.pghtb_type_geometry VALUES (1, 'POINT');
INSERT INTO pghydro.pghtb_type_geometry VALUES (2, 'LINESTRING');
INSERT INTO pghydro.pghtb_type_geometry VALUES (3, 'POLYGON');
INSERT INTO pghydro.pghtb_type_geometry VALUES (4, 'MULTIPOINT');
INSERT INTO pghydro.pghtb_type_geometry VALUES (5, 'MULTILINESTRING');
INSERT INTO pghydro.pghtb_type_geometry VALUES (6, 'MULTIPOLYGON');
INSERT INTO pghydro.pghtb_type_geometry VALUES (7, 'GEOMETRY');
INSERT INTO pghydro.pghtb_type_geometry VALUES (8, 'GEOMETRYCOLLECTION');
--
DELETE FROM pghydro.pghtb_type_relationship_class;
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (1, 1, 'POINT', 1, 'POINT', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (15, 1, 'POINT', 2, 'LINESTRING', 2, 'TOUCH', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (16, 1, 'POINT', 3, 'POLYGON', 2, 'TOUCH', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (21, 3, 'POLYGON', 3, 'POLYGON', 3, 'OVERLAP', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (20, 2, 'LINESTRING', 2, 'LINESTRING', 3, 'OVERLAP', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (19, 3, 'POLYGON', 3, 'POLYGON', 2, 'TOUCH', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (18, 2, 'LINESTRING', 2, 'LINESTRING', 2, 'TOUCH', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (17, 2, 'LINESTRING', 3, 'POLYGON', 2, 'TOUCH', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (2, 1, 'POINT', 2, 'LINESTRING', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (3, 1, 'POINT', 3, 'POLYGON', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (4, 2, 'LINESTRING', 3, 'POLYGON', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (5, 2, 'LINESTRING', 2, 'LINESTRING', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (6, 3, 'POLYGON', 3, 'POLYGON', 5, 'DISJOINT', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (7, 2, 'LINESTRING', 3, 'POLYGON', 4, 'CROSS', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (8, 2, 'LINESTRING', 2, 'LINESTRING', 4, 'CROSS', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (9, 1, 'POINT', 1, 'POINT', 1, 'IN', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (10, 1, 'POINT', 2, 'LINESTRING', 1, 'IN', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (11, 1, 'POINT', 3, 'POLYGON', 1, 'IN', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (12, 2, 'LINESTRING', 3, 'POLYGON', 1, 'IN', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (13, 2, 'LINESTRING', 2, 'LINESTRING', 1, 'IN', NULL, NULL);
INSERT INTO pghydro.pghtb_type_relationship_class VALUES (14, 3, 'POLYGON', 3, 'POLYGON', 1, 'IN', NULL, NULL);
--
DELETE FROM pghydro.pghtb_type_topology_relationship;
INSERT INTO pghydro.pghtb_type_topology_relationship VALUES (1, 'IN');
INSERT INTO pghydro.pghtb_type_topology_relationship VALUES (2, 'TOUCH');
INSERT INTO pghydro.pghtb_type_topology_relationship VALUES (3, 'OVERLAP');
INSERT INTO pghydro.pghtb_type_topology_relationship VALUES (4, 'CROSS');
INSERT INTO pghydro.pghtb_type_topology_relationship VALUES (5, 'DISJOINT');
--
DELETE FROM pghydro.pghtb_type_domain;
INSERT INTO pghydro.pghtb_type_domain VALUES (0, 'Estadual');
INSERT INTO pghydro.pghtb_type_domain VALUES (1, 'Federal');
INSERT INTO pghydro.pghtb_type_domain VALUES (2, 'Internacional');
INSERT INTO pghydro.pghtb_type_domain VALUES (3, 'Linha de Costa');
--
DELETE FROM pghydro.pghtb_primary_key_columns;
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline', 'sho_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_domain', 'tdm_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_area', 'dra_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse', 'wtc_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghft_watershed', 'wts_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_de9im', 'dim_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_geometry', 'tgm_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_topology_relationship', 'tpr_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_connection', 'tcn_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_generic', 'tng_pk');
INSERT INTO pghydro.pghtb_primary_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_specific', 'tns_pk');
--
DELETE FROM pghydro.pghtb_foreign_key_columns;
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_drn_pk', current_database(), 'pghydro', 'pghft_drainage_line', 'drn_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_dra_pk', current_database(), 'pghydro', 'pghft_drainage_area', 'dra_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_wtc_pk', current_database(), 'pghydro', 'pghft_watercourse', 'wtc_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_drp_pk', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_sho_pk', current_database(), 'pghydro', 'pghft_shoreline', 'sho_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_drp_pk', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_sho_pk', current_database(), 'pghydro', 'pghft_shoreline', 'sho_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_drp_pk', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_drp_pk', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tgm_pk_class_a', current_database(), 'pghydro', 'pghtb_type_geometry', 'tgm_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_rcl_pk_drp', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_drp_pk', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_rcl_pk_drp', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_rcl_pk_drp', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_rcl_pk_drp', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_rcl_pk_drp', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tgm_pk_class_b', current_database(), 'pghydro', 'pghtb_type_geometry', 'tgm_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_drp_pk_sourcenode', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_wtc_pk', current_database(), 'pghydro', 'pghft_watercourse', 'wtc_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_wtc_pk', current_database(), 'pghydro', 'pghft_watercourse', 'wtc_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_wtc_pk', current_database(), 'pghydro', 'pghft_watercourse', 'wtc_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_dim_pk', current_database(), 'pghydro', 'pghtb_type_de9im', 'dim_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_drp_pk_targetnode', current_database(), 'pghydro', 'pghft_drainage_point', 'drp_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_rcl_pk_wtc', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_rcl_pk_wtc', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_rcl_pk_wtc', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tpr_pk', current_database(), 'pghydro', 'pghtb_type_topology_relationship', 'tpr_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_drp_targetnode', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_drp_sourcenode', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_dra_pk', current_database(), 'pghydro', 'pghft_drainage_area', 'dra_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_dra', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_wtc', current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_tdm_pk', current_database(), 'pghydro', 'pghtb_type_domain', 'tdm_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse', 'wtc_tdm_pk', current_database(), 'pghydro', 'pghtb_type_domain', 'tdm_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tns_pk', current_database(), 'pghydro', 'pghtb_type_name_specific', 'tns_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tng_pk', current_database(), 'pghydro', 'pghtb_type_name_generic', 'tng_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tcn_pk', current_database(), 'pghydro', 'pghtb_type_name_connection', 'tcn_pk');
INSERT INTO pghydro.pghtb_foreign_key_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_tnc_pk', current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_pk');
--
DELETE FROM pghydro.pghtb_index_columns;
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_drn_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_dra_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_wtc_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_drp_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_sho_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_drp_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_sho_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_drp_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_drp_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tgm_pk_class_a', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_rcl_pk_drp', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_drp_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_starting_point', 'ssp_rcl_pk_drp', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_shoreline_ending_point', 'sep_rcl_pk_drp', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_rcl_pk_drp', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_rcl_pk_drp', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tgm_pk_class_b', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_drp_pk_sourcenode', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_wtc_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_wtc_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_wtc_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_dim_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_drp_pk_targetnode', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_starting_point', 'wsp_rcl_pk_wtc', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_stream_mouth', 'stm_rcl_pk_wtc', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse_ending_point', 'wep_rcl_pk_wtc', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_relationship_class', 'rcl_tpr_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_drp_targetnode', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_drp_sourcenode', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_dra_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_dra', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_rcl_pk_wtc', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_tdm_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_watercourse', 'wtc_tdm_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_point', 'drp_nu_valence', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_hydro_intel', 'hin_strahler', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_area', 'dra_cd_pfafstetterbasin', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_area', 'dra_nu_pfafstetterbasincodelevel', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tng_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tcn_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghtb_type_name_complete', 'tnc_tns_pk', 'btree');
INSERT INTO pghydro.pghtb_index_columns VALUES (current_database(), 'pghydro', 'pghft_drainage_line', 'drn_tnc_pk', 'btree');
---------------------------------------------------------------------------------------------------
--PGHYDRO FUNCTIONS
---------------------------------------------------------------------------------------------------
----------------------------------------------------
--FUNCTION pghydro.pghfn_DropPrimaryKeys()
----------------------------------------------------
CREATE OR REPLACE FUNCTION pghydro.pghfn_DropPrimaryKeys()
RETURNS varchar AS
$$
DECLARE
r record;
time_ timestamp;
BEGIN
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS IN : %', time_;
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 1 : %', time_;
FOR r IN SELECT f_table_catalog, f_table_schema, f_table_name, f_primary_key_column FROM pghydro.pghtb_primary_key_columns
LOOP
EXECUTE '
ALTER TABLE ONLY '||r.f_table_schema||'.'||r.f_table_name||' DROP CONSTRAINT IF EXISTS '||r.f_primary_key_column||'_pkey;
';
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$$
LANGUAGE PLPGSQL;
-----------------------------------------
--FUNCTION pghydro.pghfn_AddPrimaryKeys()
-----------------------------------------
CREATE OR REPLACE FUNCTION pghydro.pghfn_AddPrimaryKeys()
RETURNS varchar AS
$$
DECLARE
r record;
time_ timestamp;
BEGIN
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS IN : %', time_;
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 1 : %', time_;
PERFORM pghydro.pghfn_DropPrimaryKeys();
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 2 : %', time_;
FOR r IN SELECT f_table_catalog, f_table_schema, f_table_name, f_primary_key_column FROM pghydro.pghtb_primary_key_columns
LOOP
EXECUTE '
ALTER TABLE ONLY '||r.f_table_schema||'.'||r.f_table_name||' ADD CONSTRAINT '||r.f_primary_key_column||'_pkey PRIMARY KEY ('||r.f_primary_key_column||');
';
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$$
LANGUAGE PLPGSQL;
----------------------------------------------------
--FUNCTION pghydro.pghfn_DropForeignKeys()
----------------------------------------------------
CREATE OR REPLACE FUNCTION pghydro.pghfn_DropForeignKeys()
RETURNS varchar AS
$$
DECLARE
r record;
time_ timestamp;
BEGIN
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS IN : %', time_;
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 1 : %', time_;
FOR r IN SELECT f_table_catalog, f_table_schema, f_table_name, f_foreign_key_column FROM pghydro.pghtb_foreign_key_columns
LOOP
EXECUTE '
ALTER TABLE ONLY '||r.f_table_schema||'.'||r.f_table_name||' DROP CONSTRAINT IF EXISTS '||r.f_foreign_key_column||'_fkey;
';
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$$
LANGUAGE PLPGSQL;
-----------------------------------------
--FUNCTION pghydro.pghfn_AddForeignKeys()
-----------------------------------------
CREATE OR REPLACE FUNCTION pghydro.pghfn_AddForeignKeys()
RETURNS varchar AS
$$
DECLARE
r record;
time_ timestamp;
BEGIN
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS IN : %', time_;
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 1 : %', time_;
PERFORM pghydro.pghfn_DropForeignKeys();
time_ := timeofday();
RAISE NOTICE 'BEGIN OF PROCESS 2 : %', time_;
FOR r IN SELECT f_table_catalog, f_table_schema, f_table_name, f_foreign_key_column, f_table_catalog_reference, f_table_schema_reference, f_table_name_reference, f_primary_key_column_reference FROM pghydro.pghtb_foreign_key_columns
LOOP
EXECUTE '
ALTER TABLE ONLY '||r.f_table_schema||'.'||r.f_table_name||' ADD CONSTRAINT '||r.f_foreign_key_column||'_fkey FOREIGN KEY ('||r.f_foreign_key_column||') REFERENCES '||r.f_table_schema_reference||'.'||r.f_table_name_reference||'('||r.f_primary_key_column_reference||');
';
END LOOP;
time_ := timeofday();
RAISE NOTICE 'END OF PROCESS IN : %', time_;
RETURN 'OK';
END;
$$
LANGUAGE PLPGSQL;
----------------------------------------------------
--FUNCTION pghydro.pghfn_DropGeometryIndex()
----------------------------------------------------