![](/img/trans.png)
[英]How to update one column of table with 8 million rows of data in PostgreSQL
[英]Update column for few million rows in one table
我需要從一張表中更新兩列,這意味着幾百萬行。 最有效的方法是什么?
將會是這樣的:
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD'),
column_two = to_date('11/11/11', 'RR/MM/DD');
或這個:
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD');
update my_table set column_two = to_date('11/11/11', 'RR/MM/DD');
還是有更好的方法?
更新具有百萬行的表的最有效方法是根本不執行更新操作,而是創建具有更新值的新表。
- 創建時使用更新的列創建一個新表。
- 注意所有的同義詞,授權,約束,索引。
- 放下舊桌子。
- 將新表重命名為舊表。
- 重新創建的贈款,同義詞,約束,索引。
如果您不想創建一個新表,只需將其分解成幾塊即可。
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD'),
column_two = to_date('11/11/11', 'RR/MM/DD')
where rownum < 1000
AND column_one <> to_date('11/11/11', 'RR/MM/DD')
AND column_two <> to_date('11/11/11', 'RR/MM/DD');
@Incognito的答案可能更有效。 如果您要表示“高效”的意思是花費更少的時間來編寫代碼,請嘗試這種方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.