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

推荐订阅源

Google DeepMind News
Google DeepMind News
D
DataBreaches.Net
C
Check Point Blog
I
InfoQ
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
月光博客
月光博客
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
博客园 - Franky
博客园_首页
罗磊的独立博客
量子位
美团技术团队
T
The Blog of Author Tim Ferriss
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
爱范儿
爱范儿
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Martin Fowler
Martin Fowler
博客园 - 叶小钗
aimingoo的专栏
aimingoo的专栏

博客园 - 狗狗听话

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()