반응형

/********************************************************************************************
-- Title : [9.2] UTF-8 파일 COPY 로드시 BOM 에러 (Byte Order Mark)
-- Key word : utf-8 utf8 bom copy bulk load bulk insert bomremover.sh bomremover.exe
                     byte order mark
********************************************************************************************/

-- 테이블 초기화
drop table mapbak.tbl_bulk;

-- 테이블 생성
create table mapbak.tbl_bulk
( id int not null primary key
, key_num char(13) not null
, appl_num varchar(20) not null
, appl_dt char(8) not null
, sect_cntnt varchar(50) null
);

-- 파일 생성
Linux) ttt_made_on_linux.txt
1$2983001000001$1973-0002186$19731229$B65H-075/22_07 19 2013  2:04PM
2$2983002000001$1974-0000132$19740101$B32B-001/00~7/00_07 19 2013  2:04PM
3$2983002000002$1974-0000298$19740101$H01J-031/58_07 19 2013  2:04PM
4$2983002000003$1974-0001034$19740101$A01D-037/00_07 19 2013  2:04PM
5$2983002000004$1974-0001386$19740204$F25D-025/00_07 19 2013  2:04PM

Windows) ttt_made_on_windows.txt
1$2983001000001$1973-0002186$19731229$B65H-075/22_07 19 2013 2:04PM
2$2983002000001$1974-0000132$19740101$B32B-001/00~7/00_07 19 2013 2:04PM
3$2983002000002$1974-0000298$19740101$H01J-031/58_07 19 2013 2:04PM
4$2983002000003$1974-0001034$19740101$A01D-037/00_07 19 2013 2:04PM
5$2983002000004$1974-0001386$19740204$F25D-025/00_07 19 2013 2:04PM
    ※ UTF-8 변환시 Windows에서는 NOEPAD++을 이용하여 UTF-8 (with BOM) 설정.

-- without BOM 로딩(리눅스에서 만든 파일)
-- LINUX에서는 without BOM이 default라 정상 처리됨.
copy mapbak.tbl_bulk from '/home/postgres/bulk/ttt_made_on_linux.txt' with delimiter '$';

select * from abpak.tbl_bulk;

-- wth BOM 로딩(윈도우에서 만든 파일)
-- LINUX에서는 without BOM이 default라 첫 문자에 BOM byte(2)가 붙어 오류 발생.
copy mapbak.tbl_bulk from '/home/postgres/bulk/ttt_made_on_windows.txt' with delimiter '$';

********** 오류 **********
ERROR: invalid input syntax for integer: "1"
SQL 상태:22P02
컨텍스트:COPY tbl_bulk, line 1, column id: "1"

-- bom문자 제거해 주는 .sh 및 .exe 파일

bomremover.sh
다운로드

 

 

 

 

 

 

 

 

반응형

+ Recent posts