惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Y
Y Combinator Blog
T
Tailwind CSS Blog
D
Docker
博客园 - Franky
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Google DeepMind News
Google DeepMind News
腾讯CDC
Vercel News
Vercel News
Engineering at Meta
Engineering at Meta
U
Unit 42
The Cloudflare Blog
S
SegmentFault 最新的问题
WordPress大学
WordPress大学
爱范儿
爱范儿
Recent Announcements
Recent Announcements
博客园 - 聂微东
博客园 - 叶小钗
H
Help Net Security
MyScale Blog
MyScale Blog

博客园 - 狗狗听话

SpringBoot学习之缓存@Caching, @Cacheable,@CacheEvict Java学习之 EasyExcel Java学习之LocalDateTime, LocalDate, LocalTime python在某个目录下的查找指定文件夹 SpringBoot学习之JPA设置多个主键的方法 SpringBoot学习之文件上传(利用postman测试) SpringBoot学习之文件上传,下载 Python常用的语法糖 Python学习之datetime Java学习之 stream 常用方法 SpringBoot学习之使用idea打包jar文件 React学习之数组 Java学习之日期时间转换 Java读取execl 利用JDBC插入Postgresql简单示例 Springboot中项目启动加载的几种方式 Java selenium实现浏览器ctrl + s功能 Macbook pro 安装Redis Macbook pro 打开pgAmin报错 SpringBoot学习之任务定时器 关于git rebase中的一些问题:Git报错“no branch, rebasing master”
Python使用psycopg2的copy_from方法高效的大量数据批量导入
狗狗听话 · 2026-02-09 · via 博客园 - 狗狗听话

    def copy_markettrend_resume_db(self):

        try:

            conn = psycopg2.connect(

                dbname="your_db",

                user="your_user",

                password="your_password",

                host="localhost",

                port="5432"

            )

            with conn.cursor() as cursor:

                with open(self.bbo_csv, "r", encoding="utf-8") as csv_file:

                    next(csv_file)  # 跳过header

                    cursor.copy_from(csv_file, "t_market_trend_hist", sep=",")

                conn.commit()

        except Exception as e:

            self.logger.error(e)

            if conn:

                conn.rollback()