擅长:python、mysql、java
<blockquote>
<p>I'm writing all the data I need to upload in a .txt file and I'm using the COPY command from postgreSQL to transfer the file to the destination table.</p>
</blockquote>
<p>对于你所有的数据来说,这是一个沉重而不必要的往返。因为内存中已经有它,所以应该直接将其转换为多行插入:</p>
<pre><code>INSERT INTO table(col1, col2) VALUES (val1, val2), (val3, val4), ...
</code></pre>
<p>也就是说,将数据连接到这样的查询中并按原样执行。在</p>
<p>在您的例子中,您可能会根据您的需求生成并执行50个这样的插入,每个插入包含2500行。在</p>
<p>它将是性能最好的解决方案;)</p>