postgresql没有自带的批量导入导出成CSV的指令,但是有一个调用执行文件的指令(\i),这个指令可以执行编写的脚本。例如 一个a.txt文件,里面内容是
#将xxx表数据导出xxx文件 \copy xxx to xxx
需要在客户端的指令界面执行以下指令
\i 路径\a.txt
就可以进行批量导出操作。
注意COPY只能用于表,不能用于视图
copy命令可以操作的文件类型有:txt、sql、csv、压缩文件、二进制格式
1、copy命令导入数据示例:tb2是表名,delimiter ‘,’ 表示按逗号分隔字段数据
postgresql=# copy tb2 from '/mnt/postgresql/weibo.1000'delimiter ','; COPY1000 postgresql=# select count(*)from tb2;2、copy命令导入导出数据为sql格式
postgresql=# COPY tb2 TO '/mnt/postgresql/weibo.sql'; COPY1000 postgresql=# COPY tb2 from '/mnt/postgresql/weibo.sql'; COPY2000导出表 employee 到 sql 文件:
psql> COPY employee TO '/home/smallfish/employee.sql';从文件导入数据:
psql> COPY employeenew FROM '/home/smallfish/employee.sql';导入文件数据,指定间隔符为 | :
psql> COPY employeenew FROM '/home/smallfish/employee.sql' DELIMITER |;导出数据库及具体表
1.导出数据库:方式一:pg_dump -U postgres -f c:\db.sqlpostgis
方式二:pg_dump -Upostgres postgis > c:\db.sql
2.导入数据库:方式一:psql -d postgis -f c:\db.sql postgres
3.导出具体表:方式一:pg_dump -Upostgres -t mytable -f dump.sql postgres
4.导入具体表:方式一:psql -d postgis -f c:\ dump.sqlpostgres
参数:
postgres:用户
postgis:数据库名称
mytable:表名称
-f, --file=文件名:输出文件名
-U, --username=名字:以指定的数据库用户联接
数据库导入导出
参考链接 : https://blog.csdn.net/sinat_33775006/article/details/101181769 postgresql 数据导入导出https://blog.csdn.net/sanjiaoqq/article/details/84441053 更多介绍 :postgresql copy命令介绍 https://www.cnblogs.com/xiaodf/p/5027196.html
PostgreSQL COPY 导入/导出数据 : http://ju.outofmemory.cn/entry/35794 https://yq.aliyun.com/articles/74420
https://www.cnblogs.com/junge8618/p/5513966.html POSTGRESQL 数据库导入导出 :https://blog.csdn.net/qq_23077579/article/details/81780669 postgresql 数据导入导出 :https://blog.csdn.net/sanjiaoqq/article/details/84441053