Import : CSV -> Table


형식

COPY {테이블명}
[ (컬럼 목록) ]
FROM '{파일경로}'
WITH [DELIMITER E'{컬럼구분문자}]
     [파일형식]
     [HEADER]
     [ENCODING '{인코딩}']
;

예시

COPY RAW_ADM_SIGBJD
FROM '/docker-entrypoint-initdb.d/data/adm/sigungu_bjd_code.csv'
WITH DELIMITER E'\\\\t'
     CSV
     HEADER
     ENCODING 'UTF8';
COPY RC_EXPOS_PRICE
(bjdongCd, bldNm, bun, bylotCnt, crtnDay, hsprc, ji)
FROM '/docker-entrypoint-initdb.d/data/pub/RC_EXPOS_PRICE.csv'
WITH DELIMITER E'\\\\t' ENCODING 'UTF8' CSV HEADER;

Export : Table -> CSV


형식

COPY (
    SELECT {컬럼들}
    FROM {테이블명}
)
TO '{파일 경로}'
WITH [DELIMITER E'{컬럼구분문자}']
     [ENCODING '{인코딩}']
     [{파일형식}]
;

예시

COPY (
    SELECT  SIG_BJD_CD
           ,LV
           ,UP_SIG_BJD_CD
           ,ADDR_NM
           ,FULL_ADDR_NM
           ,EXIST_YN
           ,LAST_YN
           ,SPACE_POS
           ,CREATED_AT
           ,UPDATED_AT
    FROM ADM_SIGBJD
)
TO '/docker-entrypoint-initdb.d/starter-pack/ADM_SIGBJD.csv'
WITH DELIMITER E'\\\\t'
     ENCODING 'UTF8'
     CSV;

Copy 성능 향상시키기


ALTER TABLE {테이블명} DISABLE TRIGGER ALL;

UPDATE pg_index SET indisready = false
WHERE indrelid = (
    SELECT oid
    FROM pg_class
    WHERE relname=LOWER('{테이블명}')
);

---------------
-> COPY 쿼리 <-
---------------

UPDATE pg_index SET indisready = true
WHERE indrelid = (
    SELECT oid
    FROM pg_class
    WHERE relname=LOWER('{테이블명}')
);

ALTER TABLE {테이블명} ENABLE TRIGGER ALL;

REINDEX TABLE {테이블명};