잠시만 기다려 주세요


 
HOME   |  여기는?   |  바다물때표   |  여러가지 팁 (781)  |  추천 및 재미 (53)  |  자료실 (18)  |  끄적거림 (456)  |  시나리오 (757)  |  드라마 대본 (248)  |  

2019년 07월 20일
변해야 산다. 귀찮음은 변화를 막는 게으름의 한 형태이다. - 바다아이
 

    DATABASE

DATABASE - postgresql 우체국 도로명 주소 데이터 입력하기... 테이블 만들기.. 우편번호
이 름 : 바다아이   |   조회수 : 832         짧은 주소 : https://www.bada-ie.com/su/?461534253096
일단 아래 가셔서 지역별 주소 DB 파일을 받아옵니다. 링크 경로는 변경될 수 있습니다.

https://www.epost.go.kr/search/zipcode/areacdAddressDown.jsp

행정자치부와 우체국 2군데에서 배포하는데 행정자치부는 일일변동 사항을 바로 반영하고
우체국은 한달 단위로 데이터를 반영합니다.

파일 하나 열어 보시면 첫 줄에 항목들 필드 설명 있고 두번째 줄 부터는 데이터 입니다.

중요

압축 풀면 파일 인코딩이 euc-kr 입니다. 이거 utf-8 로 변경 후 작업하세요....
요즘 DB 거의다 utf-8 을 사용하니까요...
메모장 등등 열어서 다른이름으로 저장하면서 인코딩을 utf-8 로 변경하시면 됩니다.
17개 정도니까.. 금방 합니다. 리눅스 사용자면 iconv 바로 사용하시구요..

폴더에 가셔서 아래 입력하시면 그 폴더에 있는 파일 전부 변경합니다. hwp 파일은 지우시고요...

find . -type f -exec iconv -f cp949 -t utf-8 {} -o {}.new \; -exec rm -rf {} \; -exec mv {}.new {} \; -exec echo -n "{} ==> change ==> " \; -exec file -bi {} \;

구조는 시도 별로 17개 테이블입니다.
데이터가 워낙 커서 한 테이블로 하면 부하가 너무 큽니다.
검색창도 시도, 시군구 select 로 선택하게 하시고요.. 그게 속 편합니다.
이러면 부하 별로 안 걸립니다. 검색 데이터가 많아도 어차피 페이지 네비 하실거니까요...

postgresql 로 설명해서

17개 시도 테이블(zip_시도) 과 1개의 시군구(zip_sido_sgg) 만 모아논 테이블을 만듭니다.
아래는 스키마 입니다. 입맛에 맞게 고쳐 쓰세요...

보너스로  시도 아래 나열합니다.

{"gangwon", "jeju", "busan", "chungbuk", "chungnam", "daegu", "daejeon", "gwangju", "gyeongbuk", "gyeongnam", "gyunggi", "incheon", "jeonbuk", "jeonnam", "sejong", "seoul", "ulsan"}
{"강원도", "제주특별자치도", "부산광역시", "충청북도", "충청남도", "대구광역시", "대전광역시", "광주광역시", "경상북도", "경상남도", "경기도", "인천광역시", "전라북도", "전라남도", "세종특별자치시", "서울특별시", "울산광역시"}


일단 테이블을 만듭니다. 아래 테이블 생성 부분과 인덱스 부분만 복사해서
postgresql 명령줄에 전부 붙여 넣습니다. 마지막에 엔터 한방더 쳐서 확실히...
테이블 만드실 때 반드시 해당 사용자로 접속해서 만드세요.. 나중에 권한 없다 나오니까요 ^^;



CREATE TABLE zip_busan (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_chungbuk (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_chungnam (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_daegu (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_daejeon (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_gangwon (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_gwangju (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_gyeongbuk (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_gyeongnam (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_gyunggi (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_incheon (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_jeju (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_jeonbuk (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_jeonnam (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_sejong (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_seoul (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE TABLE zip_sido_sgg (
    sido character varying(30),
    sgg character varying(50),
    sido_e character varying(50)
);


CREATE TABLE zip_ulsan (
    zip integer NOT NULL,
    sido character varying(30) NOT NULL,
    sido_e character varying(40),
    sgg character varying(50),
    sgg_e character varying(50),
    yb character varying(50),
    yb_e character varying(50),
    road_c character varying(50) NOT NULL,
    road character varying(100),
    road_e character varying(100),
    under integer,
    gun integer,
    gun2 integer,
    gun_a character varying(50),
    many character varying(100),
    siggb character varying(100),
    dong_c character varying(50) NOT NULL,
    dong character varying(50),
    le character varying(50),
    dong2 character varying(50),
    san integer,
    ji integer,
    y_c integer,
    ji2 integer,
    zip2 character varying(50),
    zip2_c character varying(50)
);


CREATE INDEX zip2_busan_index ON zip_busan USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_chungbuk_index ON zip_chungbuk USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_chungnam_index ON zip_chungnam USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_daegu_index ON zip_daegu USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_daejeon_index ON zip_daejeon USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_gangwon_index ON zip_gangwon USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_gwangju_index ON zip_gwangju USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_gyeongbuk_index ON zip_gyeongbuk USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_gyeongnam_index ON zip_gyeongnam USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_gyunggi_index ON zip_gyunggi USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_incheon_index ON zip_incheon USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_jeju_index ON zip_jeju USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_jeonbuk_index ON zip_jeonbuk USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_jeonnam_index ON zip_jeonnam USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_sejong_index ON zip_sejong USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_seoul_index ON zip_seoul USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip2_ulsan_index ON zip_ulsan USING btree (dong, le, dong2, ji, ji2);


CREATE INDEX zip_busan_index ON zip_busan USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_chungbuk_index ON zip_chungbuk USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_chungnam_index ON zip_chungnam USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_daegu_index ON zip_daegu USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_daejeon_index ON zip_daejeon USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_gangwon_index ON zip_gangwon USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_gwangju_index ON zip_gwangju USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_gyeongbuk_index ON zip_gyeongbuk USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_gyeongnam_index ON zip_gyeongnam USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_gyunggi_index ON zip_gyunggi USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_incheon_index ON zip_incheon USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_jeju_index ON zip_jeju USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_jeonbuk_index ON zip_jeonbuk USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_jeonnam_index ON zip_jeonnam USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_sejong_index ON zip_sejong USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_seoul_index ON zip_seoul USING btree (sgg, yb, road, gun, gun2);


CREATE INDEX zip_sido_sgg_index ON zip_sido_sgg USING btree (sido);


CREATE INDEX zip_sido_sgg_index2 ON zip_sido_sgg USING btree (sido_e);


CREATE INDEX zip_ulsan_index ON zip_ulsan USING btree (sgg, yb, road, gun, gun2);




테이블을 잘 생성했으면 이제 실제 데이터 입력입니다.
데이터 입력이 생각보다 오래 안 걸립니다. 서비스 중이라도 하나씩.... 처리 합니다.
저는 압축 푼 17개 파일을 /home2/다운로드/zipcode_DB 에 넣어 놓았습니다.
마지막 엔터 한방 더...



BEGIN WORK;
LOCK TABLE zip_gangwon IN ACCESS EXCLUSIVE MODE;
truncate zip_gangwon;
\copy zip_gangwon  from '/home2/다운로드/zipcode_DB/강원도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_jeju IN ACCESS EXCLUSIVE MODE;
truncate zip_jeju;
\copy zip_jeju  from '/home2/다운로드/zipcode_DB/제주특별자치도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_busan IN ACCESS EXCLUSIVE MODE;
truncate zip_busan;
\copy zip_busan  from '/home2/다운로드/zipcode_DB/부산광역시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_chungbuk IN ACCESS EXCLUSIVE MODE;
truncate zip_chungbuk;
\copy zip_chungbuk  from '/home2/다운로드/zipcode_DB/충청북도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_chungnam IN ACCESS EXCLUSIVE MODE;
truncate zip_chungnam;
\copy zip_chungnam  from '/home2/다운로드/zipcode_DB/충청남도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_daegu IN ACCESS EXCLUSIVE MODE;
truncate zip_daegu;
\copy zip_daegu  from '/home2/다운로드/zipcode_DB/대구광역시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_daejeon IN ACCESS EXCLUSIVE MODE;
truncate zip_daejeon;
\copy zip_daejeon  from '/home2/다운로드/zipcode_DB/대전광역시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_gwangju IN ACCESS EXCLUSIVE MODE;
truncate zip_gwangju;
\copy zip_gwangju  from '/home2/다운로드/zipcode_DB/광주광역시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_gyeongbuk IN ACCESS EXCLUSIVE MODE;
truncate zip_gyeongbuk;
\copy zip_gyeongbuk  from '/home2/다운로드/zipcode_DB/경상북도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_gyeongnam IN ACCESS EXCLUSIVE MODE;
truncate zip_gyeongnam;
\copy zip_gyeongnam  from '/home2/다운로드/zipcode_DB/경상남도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_gyunggi IN ACCESS EXCLUSIVE MODE;
truncate zip_gyunggi;
\copy zip_gyunggi  from '/home2/다운로드/zipcode_DB/경기도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_incheon IN ACCESS EXCLUSIVE MODE;
truncate zip_incheon;
\copy zip_incheon  from '/home2/다운로드/zipcode_DB/인천광역시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_jeonbuk IN ACCESS EXCLUSIVE MODE;
truncate zip_jeonbuk;
\copy zip_jeonbuk  from '/home2/다운로드/zipcode_DB/전라북도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_jeonnam IN ACCESS EXCLUSIVE MODE;
truncate zip_jeonnam;
\copy zip_jeonnam  from '/home2/다운로드/zipcode_DB/전라남도.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_sejong IN ACCESS EXCLUSIVE MODE;
truncate zip_sejong;
\copy zip_sejong  from '/home2/다운로드/zipcode_DB/세종특별자치시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_seoul IN ACCESS EXCLUSIVE MODE;
truncate zip_seoul;
\copy zip_seoul  from '/home2/다운로드/zipcode_DB/서울특별시.txt' with delimiter '|' csv header;
COMMIT WORK;

BEGIN WORK;
LOCK TABLE zip_ulsan IN ACCESS EXCLUSIVE MODE;
truncate zip_ulsan;
\copy zip_ulsan  from '/home2/다운로드/zipcode_DB/울산광역시.txt' with delimiter '|' csv header;
COMMIT WORK;


시군구만 빼서 zip_sido_sgg 테이블에 넣습니다. 마지막 엔터 한방 더...


BEGIN WORK;

LOCK TABLE zip_sido_sgg  IN ACCESS EXCLUSIVE MODE;

truncate zip_sido_sgg;

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'gangwon' from zip_gangwon);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'jeju' from zip_jeju);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'busan' from zip_busan);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'chungbuk' from zip_chungbuk);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'chungnam' from zip_chungnam);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'daegu' from zip_daegu);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'daejeon' from zip_daejeon);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'gwangju' from zip_gwangju);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'gyeongbuk' from zip_gyeongbuk);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'gyeongnam' from zip_gyeongnam);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'gyunggi' from zip_gyunggi);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'incheon' from zip_incheon);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'jeonbuk' from zip_jeonbuk);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'jeonnam' from zip_jeonnam);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'sejong' from zip_sejong);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'seoul' from zip_seoul);

insert into zip_sido_sgg  (sido, sgg, sido_e) (select distinct sido, sgg, 'ulsan' from zip_ulsan);

COMMIT WORK;


끝..... 잘 사용하세요....
한달에 한번 정도 업데이트 하면 되니까... 우체국에서 받아서 처리하세요...
주소 변동이 중요한 사람은 행정자치부에서 매일매일 파일 직접 받아서 따로 변경하셔야 합니다.


검색 포인트는 도로명일 때는 sgg, road, gun, gun2
동으로 검색시에는 sgg, dong, dong2, le, ji, ji2
근데 띄어쓰기 문제가 있으니까... 빈값 제거해서 비교하세요....
도로명은 road 에 핵심이 있고... 동검색은 dong, dong2, le 세개가 or 연산자로 가야 합니다.
가져오는 필드는 보셔서 필요한 거 조합하시면 됩니다. 산이나 기타 길게 나올 만한 주소 하나 보셔서 필요한 항목들 사용하세요...


그리고 zip_sido_sgg 시군구 모아논 것은 sgg 로 distinct 로 해서 select 날리시면 됩니다. 조건은 sido_e 나 sido 에 거시고요...
그럼 중복값 제거 후 해당 시군구가 나오겠네요...

p.s
null 값 받으실 때 주의하세요... 언어별로 드라이버가 null 에 오류 반응을 해서 형을 다른 형으로 받아야 할 때 있습니다.
 
| |


      1 page / 3 page
번 호 카테고리 제 목 이름 조회수
72 DATABASE db .. dbeaver, db admin tool 바다아이 569
71 DATABASE postgresql SEQUENCE reset .... 바다아이 575
70 DATABASE mysql, mariadb , , , , left, substring, right, concat 바다아이 930
69 DATABASE [PostgreSql] WITH , , Operator 바다아이 692
68 DATABASE postgresql for, foreach , 바다아이 719
67 DATABASE postgresql , , into ... 바다아이 675
66 DATABASE postgresql PL/pgSQL - SQL Procedural Language, , 바다아이 2620
현재글 DATABASE postgresql ... .. 바다아이 833
64 DATABASE postgresql CSV export/import 바다아이 856
63 DATABASE postgresql tablespace , .... 바다아이 997
62 DATABASE postgresql 10 partitioning, ... , ... 바다아이 786
61 DATABASE Using PostgreSQL Arrays, ... ... 바다아이 862
60 DATABASE PostgreSQL (TRIGGER) (function) 바다아이 804
59 DATABASE mysql, mariadb DISTINCT GROUP BY 바다아이 785
58 DATABASE Optimize and Improve PostgreSQL Performance with VACUUM, ANALYZE, and REINDEX 바다아이 846
57 DATABASE postgresql tuple . vacuumdb .. , . 바다아이 860
56 DATABASE RDBMS SQL MONGODB ... 바다아이 791
55 DATABASE mysql 5.x my.cnf 바다아이 982
54 DATABASE postgresql , .. 바다아이 1083
53 DATABASE postgresql , size, 바다아이 1324
52 DATABASE postgresql , , .... 바다아이 940
51 DATABASE PostgreSQL Replication, , , master, slave 바다아이 1190
50 DATABASE postgresql case 바다아이 1002
49 DATABASE postgresql with 바다아이 981
48 DATABASE postgresql , , string 바다아이 1127
47 DATABASE / SELECT , 바다아이 1071
46 DATABASE Postgresql partitioning table , , , 바다아이 1138
45 DATABASE PostgreSQL 바다아이 1250
44 DATABASE postgresql vacuumdb, psql, pg_dump password crontab 바다아이 1394
43 DATABASE postgresql sequence 퀀 auto_increment . 바다아이 1772
| |






Copyright ⓒ 2001.12. bada-ie.com. All rights reserved.
이 사이트는 리눅스에서 firefox 기준으로 작성되었습니다. 기타 브라우저에서는 다르게 보일 수 있습니다.
[ FreeBSD + GoLang + PostgreSQL ]
서버위치 : New Jersey  실행시간 : 0.05648
to webmaster... gogo sea. gogo sea.