In PL/PgSQL FOR loops the iterator is automatically declared, and this could bring some problems.
FOR loops automatically declared variables in PL/PgSQL
Consider the following simple...
PL/PgSQL中的FOR循环会自动声明变量,变量名默认为整型且仅在循环内部存在。解决方法是选择适当的迭代器名称并相应地设置返回变量。