如何避免在PostgreSQL中多次插入 [英] How to avoid multiple insert in PostgreSQL

查看:112
本文介绍了如何避免在PostgreSQL中多次插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的查询中,我使用for循环。每次执行for循环时,最后都必须将一些值插入表中。这很耗时,因为for循环有很多记录。因此,每次执行for循环时,都会发生插入。在执行for循环后,是否还有其他方法可以在末尾执行插入操作。

In my query im using for loop. Each and every time when for loop is executed, at the end some values has to be inserted into table. This is time consuming because for loop has many records. Due to this each and every time when for loop is executed, insertion is happening. Is there any other way to perform insertion at the end after the for loop is executed.

For i in 1..10000 loop .... 
    --coding 
    insert into datas.tb values(j,predictednode); -- j and predictednode are variables which will change for every loop
End loop;

我不想每次插入都希望插入在末尾。

Instead of inserting each and every time i want the insertion should happen at the end.

推荐答案

如果您显示变量的计算方式,则可以构建如下所示的东西:

If you show how the variables are calculated it could be possible to build something like this:

insert into datas.tb
select
    calculate_j_here,
    calculate_predicted_node_here
from generate_series(1, 10000)

这篇关于如何避免在PostgreSQL中多次插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆