-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfill.tables.sql
More file actions
98 lines (95 loc) · 3.28 KB
/
fill.tables.sql
File metadata and controls
98 lines (95 loc) · 3.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
+insert into kladr_region
(code,name, socr, index,gninmb,uno,ocatd,status)
select code,name, socr, index,gninmb,uno,ocatd,status
from kladr
where code like '%000000000__';
(code,name, socr, index,gninmb,uno,ocatd,status)
select code,name, socr, index,gninmb,uno,ocatd,status
from kladr
where not code like '%000000000__'
and code like '%000000__';
insert into kladr_city
(code,name, socr, index,gninmb,uno,ocatd,status)
select code,name, socr, index,gninmb,uno,ocatd,status
from kladr
where not code like '%000000__'
and code like '%000__'
insert into kladr_ville
(code,name, socr, index,gninmb,uno,ocatd,status)
select code, name, socr, index,gninmb,uno,ocatd,status
from kladr
where not code like '%000__'
--create or replace function regionid(IN r TEXT)
-- RETURNS CHARACTER VARYING(20) as $$
-- DECLARE t CHARACTER VARYING(20);
-- BEGIN
-- select overlay(r placing repeat('0',char_length(r)-4) from 3 ) into t;
-- RETURN t;
-- END;
--$$ LANGUAGE plpgsql;
--
--create or replace function regionfid(IN r TEXT)
-- RETURNS CHARACTER VARYING(20) as $$
-- DECLARE t CHARACTER VARYING(20);
-- BEGIN
-- select newcode from altnames into t where oldcode=r;
-- select COALESCE(t,r) into r;
-- select overlay(r placing repeat('0',char_length(r)-4) from 3 ) into t;
-- RETURN t;
-- END;
--$$ LANGUAGE plpgsql;
--
--create or replace function districtid(IN r TEXT)
-- RETURNS CHARACTER VARYING(20) as $$
-- DECLARE t CHARACTER VARYING(20);
-- BEGIN
-- select overlay(r placing repeat('0',char_length(r)-7) from 6 ) into t;
-- RETURN t;
-- END;
--$$ LANGUAGE plpgsql;
--
--create or replace function districtfid(IN r TEXT)
-- RETURNS CHARACTER VARYING(20) as $$
-- DECLARE t CHARACTER VARYING(20);
-- BEGIN
-- select newcode from altnames into t where oldcode=r;
-- select COALESCE(t,r) into r;
-- select overlay(r placing repeat('0',char_length(r)-7) from 6 ) into t;
-- RETURN t;
-- END;
--$$ LANGUAGE plpgsql;
--
--
--
--INSERT INTO kladr_region
-- (code,name, socr, index,gninmb,uno,ocatd,status)
-- select regionid(code) as code,name, socr, index,gninmb,uno,ocatd,status
-- from kladr
-- where code like '%000000000__';
--
--INSERT INTO kladr_district
-- (code,name, socr, index,gninmb,uno,ocatd,status,region_id)
-- select districtid(code) as code,
-- name, socr, index,gninmb,uno,ocatd,status, regionfid(code) as region_id
-- from kladr
-- where not code like '%000000000__'
-- and code like '%000000__'
-- and code like '55%'
--INSERT INTO kladr_city
-- (code,name, socr, index,gninmb,uno,ocatd,status,region_id,district_id)
-- select cityid(code) as code,
-- name, socr, index,gninmb,uno,ocatd,status, regionfid(code) as region_id, districtfid(code) as district_id
-- from kladr
-- where not code like '%000000__'
-- and code like '%000__'
-- and code like '55%'
-- and substr(code,1,5) not like '%000';
--INSERT INTO kladr_city
-- (code,name, socr, index,gninmb,uno,ocatd,status,region_id,district_id)
-- select cityid(code) as code,
-- name, socr, index,gninmb,uno,ocatd,status, regionfid(code) as region_id, null as district_id
-- from kladr
-- where not code like '%000000__'
-- and code like '%000__'
-- and code like '55%'
-- and substr(code,1,5) like '%000';