postgre 导出单表和导入

pg除了可以通过dump的方式导入和导出。如果只是导出数据,可以直接使用copy

导出

COPY user TO '/tmp/data/test.csv' WITH csv;
COPY user(name,password) TO '/tmp/data/test.csv' WITH csv;
COPY (select * from user) TO '/tmp/data/test.csv' WITH csv;
COPY (select name,age from user) TO '/tmp/data/test.csv' WITH csv header;

注意,远程连接也只会导出文件的数据库所在的目录。

语法

COPY { table_name [ ( column_name [, ...] ) ] | ( query ) }
    TO { 'filename' | PROGRAM 'command' | STDOUT }
    [ [ WITH ] ( option [, ...] ) ]

导入

COPY user_1 FROM '/tmp/data/test.csv' WITH csv;

语法

COPY table_name [ ( column_name [, ...] ) ]
    FROM { 'filename' | PROGRAM 'command' | STDIN }
    [ [ WITH ] ( option [, ...] ) ]
posted @ 2018-12-21 18:39  Ryan.Miao  阅读(1223)  评论(0编辑  收藏  举报