python中数据库游标的使用总结

python中游标具体使用方式

简单总结游标or流式读取的这块使用方式,具体使用方式还是得看官方文档。游标使用场景适合于超大规模的数据库数据读取。具体可以看我上篇文章:从数据库读取大量数据的方式对比

psycopg2

适用对象:mysql数据库
postgresql提供了数据库游标的方式,可以不用一次性读到程序内存里,而是分多次加载到内存里,按批处理。

psycopg官方文档连接

cursor ( name=None , cursor_factory=None , scrollable=None , withhold=False )

Return a new cursor object using the connection.

If name is specified, the returned cursor will be a server side cursor (also known as named cursor ). Otherwise it will be a regular client side cursor. By default a named cursor is declared without SCROLL option and WITHOUT HOLD : set the argument or property scrollable to True / False and or withhold to True to change the declaration.

使用操作:

  1. 指定cursor名字:psycopg2_conn.cursor(name=‘name_of_cursor’) (划重点,需要赋予名字才会开启数据库的游标,不指定na
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值