[Postgres] Bulk Insert and Export Data with csv Files with Postgres copy Command
When working with databases, it seems inevitable that you will find yourself needing to export data from a table to send along to another team, company, or organization. Or vise versa, you have a file, possibly a csv, and you want to add all of it into your database. There are lots of options to do this but the easiest is by using the copy
command in Postgres.
copy <table name> <column names> from '<full file path to CSV file>' DELIMITER ',' CSV HEADER;
Ex:
copy users (first_name, last_name, email) from '/path/to/file/my-users.csv' DELIMITER ',' CSV HEADER
This comand will bulk insert all rows from the file into the table.
HEADER: is a boolean type, tell whether the first row of csv is header or not, to decide whether copy header into table or not.
If you change "from" to "to" you can export a copy of data to the file FROM the DB as a CSV.
copy users (first_name, last_name, email) to '/path/to/file/my-users-copy.csv' DELIMITER ',' CSV HEADER
分类:
Postgres
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2018-07-30 [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component
2018-07-30 [JavaEE] Testing the Java EE Application : Basic Arquillian integration test
2017-07-30 [Angular] Design API for show / hide components based on Auth
2014-07-30 [Node.js]23. Level 4: Semantic versioning
2014-07-30 [Node.js]22. Level 4: Dependency