如何批量更新400 000条记录

时间:2013-11-12 10:42:21

标签: postgresql out-of-memory batch-processing

我有下表名为business_extra

的表格
business_id    address      neighbourhood
==========================================
1
2
3
..
400 000 records

address列包含空值,因此我想使用另一个表

更新该列

我写了以下查询:

update b2g_mns_v2.txn_business_extra a 
   set mappable_address=b.mappable_address 
from b2g_mns_v2.temp_business b 
where b.import_reference_id=a.import_reference_id

但收到错误消息:

  

超出共享内存

1 个答案:

答案 0 :(得分:1)

update b2g_mns_v2.txn_business_extra a 
   set mappable_address=b.mappable_address 
from b2g_mns_v2.temp_business b 
where b.import_reference_id=a.import_reference_id
and a.mappable_address is null
limit 10000

这样做几次(10000批次)。 正如提到的a_horse_with_no_name,通过提供执行计划,可以更好地确保查询正常。