etl.py 文件源码

python
阅读 28 收藏 0 点赞 0 评论 0

项目:train-occupancy 作者: datamindedbe 项目源码 文件源码
def write_to_db(self, result, table, primary_key=None):
        if len(result) == 0:
            return
        result_string = ['(' + ','.join(['\'%s\'' % c for c in r]) + ')' for r in result]
        result_string = ',\n'.join(result_string)

        query = """
            INSERT INTO %s VALUES
              %s
        """ % (table, result_string)
        if primary_key is not None:
            query += "\nON CONFLICT (%s) DO NOTHING\n" % primary_key

        with connect(self.connection_string) as con:
            con.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
            with con.cursor() as cur:
                cur.execute(query)
                cur.close()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号