需要帮助从数组中插入数据作为输入参数,使用PostgreSQL函数
任何一个人都可以帮助在postgresql中创建函数,其中参数为insertDatausingArray(exp_ids array,group_id integer)
和内部函数以迭代数组(exp_ids) 相应地插入
数据 ,即{3275,3845,3578,3125}和group_id 1000520-所有
InsertDatausingArray({3275,3845,3578,3578,3125},1000520)
ext_ids作为数组 在这里,Staructre是这个 group_id | exp_id 数据如下:
exp_id, group_id
3275, 1000520
3845, 1000520
3578, 1000520
3125, 1000520
让我知道是否需要进一步澄清
can any one help to create function in postgresql where parameters are insertdatausingarray(exp_ids array, group_id integer)
and inside function that to iterate the array (exp_ids)
do insertion accordingly
Data
exp_ids as array i.e. {3275, 3845, 3578, 3125} and group_id 1000520 - common for all
insertdatausingarray({3275, 3845, 3578, 3125}, 1000520)
Table:
Here, staructre is this
group_id | exp_id
and data looks as below:
exp_id, group_id
3275, 1000520
3845, 1000520
3578, 1000520
3125, 1000520
let me know if any further clarification required
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要功能来执行此操作,尽管如果您真的愿意,可以将SQL放入功能中。您只需要解开阵列即可。在此示例中,我使用的是with子句传递数据,但是显然您可以以某种方式执行此操作,例如您的应用程序。
如果您确实需要一个函数,则只是包裹在功能中的查询的主要部分:
You don't need a function to do this, although you could put the SQL in a function if you really wanted to. You just need to unnest the array. In this example, I'm using a WITH clause to pass in the data, but you could obviously do this some other way, like from your application.
If you really need a function, it's just the main part of the query wrapped in a function: