1. insert into ... select ...
insert into table_name select ... from source_table;
2. insert into values(),(),...()
insert into table_name(field1,field2,..., fieldn) values(v1,v2,...vn),(...);
3. copy或\copy
能够将一定格式的文件数据导入到数据库中,相比insert效率更高,通常大数据量的文件导入一般在数据库服务器端通过Postgresql超级用户使用copy导入
将users表中的数据导出到/tmp/users.txt
copy users to '/tmp/users.txt'; -- 导出数据
查看数据
# more /tmp/users.txt
1 user_1
2 user_2
3 user_3
4 user_4
5 user_5
6 user_6
......
清空表数据
truncate table users; -- 清空表数据
将数据导入到users表
copy users from '/tmp/users.txt'; -- 导入数据
select count(*) from users;