pgloader 學習(三)快速使用

pgloader 支持多種數據源數據的加載,如下列出簡單的操做命令,後邊會有詳細的使用說明html

csv 格式內容加載

預備說明

須要先在pg 數據庫建立表mysql

create table districts_longlat
(
         usps text,
         geoid text,
         aland bigint,
         awater bigint,
         aland_sqmi double precision,
         awater_sqmi double precision,
         intptlat double precision,
         intptlong double precision
);
 

csv文件加載格式

請求格式sql

pgloader --type csv \
         --field id --field field \
         --with truncate \
         --with "fields terminated by ','" \
         ./test/data/matching-1.csv \
         postgres:///pgloader?tablename=matching

標準輸入加載數據

pgloader --type csv \
         --field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong" \
         --with "skip header = 1" \
         --with "fields terminated by '\t'" \
         - \
         postgresql:///pgloader?districts_longlat \
         < test/data/2013_Gaz_113CDs_national.txt

http 加載數據

pgloader --type csv \
         --field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong" \
         --with "skip header = 1" \
         --with "fields terminated by '\t'" \
         http://pgsql.tapoueh.org/temp/2013_Gaz_113CDs_national.txt \
         postgresql:///pgloader?districts_longlat

http 壓縮文件加載文件

curl http://pgsql.tapoueh.org/temp/2013_Gaz_113CDs_national.txt.gz \
| gunzip -c \
| pgloader --type csv \
           --field "usps,geoid,aland,awater,aland_sqmi,awater_sqmi,intptlat,intptlong"
           --with "skip header = 1" \
           --with "fields terminated by '\t'" \
           - \
           postgresql:///pgloader?districts_longlat

從sqlite 遷移數據

請求格式

createdb newdb
pgloader ./test/sqlite/sqlite.db postgresql:///newdb

從mysql 遷移數據

請求格式

createdb pagila
pgloader mysql://user@localhost/sakila postgresql:///pagila

從遠程http加載壓縮dbf 文件

請求格式

createdb foo
pgloader --type dbf http://www.insee.fr/fr/methodes/nomenclatures/cog/telechargement/2013/dbf/historiq2013.zip postgresql:///foo

說明

實際上官方代碼倉庫包含了一個test 的目錄,裏邊包含了測試腳本以及數據數據庫

參考資料

https://pgloader.readthedocs.io/en/latest/quickstart.htmlcurl

相關文章
相關標籤/搜索