PGsql实现循环插入查询出的数据

PGsql实现循环插入查询出的数据

do $$
declare 
	tmp record;

ia int := 1;

ib int := 2;

ic int := 3;

begin
   for tmp in (
select
	*
from
	xxx_table xxx
join position p 
on xxx.position_id = p.id
)   
	loop
		
insert
	into
	management_position_user 
	(position_id,user_id)
values
(tmp.position_id,
tmp.user_id);

raise notice 'position_id:%, user_id:%',
tmp.position_id,
tmp.user_id;
end loop;
end;

$$

你可能感兴趣的:(数据库,sql,数据库,postgresql)