pgloader 学习(三)快速使用

pgloader 支持多种数据源数据的加载,以下列出简单的操作命令,后边会有详细的使用说明

csv 格式内容加载

预备说明

需要先在pg 数据库创建表

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文件加载格式

请求格式

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.html

posted on   荣锋亮  阅读(1271)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)

导航

< 2025年3月 >
23 24 25 26 27 28 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 1 2 3 4 5
点击右上角即可分享
微信分享提示