postgresql , 批量 , batch , insert , update , delete , copy
如何一次插入多條記錄?
如何一次更新多條記錄?
如何一次批量删除多條記錄?
批量操作可以減少資料庫與應用程式的互動次數,提高資料處理的吞吐量。
使用insert into ... select的方法
使用values(),(),...();的方法
begin; ...多條insert...; end;
嚴格來說,這應該不屬于批量,但是可以減少事務送出時的同步等待。同樣有性能提升的效果。
copy
copy協定與insert協定不一樣,更加精簡,插入效率高。
不同的語言驅動,對應的copy接口不一樣。
參考
<a href="https://jdbc.postgresql.org/documentation/publicapi/index.html">https://jdbc.postgresql.org/documentation/publicapi/index.html</a>
<a href="https://www.postgresql.org/docs/9.6/static/libpq-copy.html">https://www.postgresql.org/docs/9.6/static/libpq-copy.html</a>
批量更新
批量删除
如果要清除全表,建議使用truncate