s

cursor in postgresql example edit button Edit

author
Murugan Andezuthu Dharmaratnam | calendar 22 September 2021 | 1691

here is a sample code to insert data into a table in postgresql using cursor.

Sample Code

declare
    cost_center   record;
    cur_costcenter  cursor for 
		select public.uuid_generate_v4() as reportid,* from costcenter;
begin
	open cur_costcenter;
	loop 
		fetch cur_costcenter into cost_center;
		exit when not found;
		
		
		insert into yourtablename(reportid, environment)
		values(cost_center.reportid, cost_center.costcentername);
		
	end loop;
	close cur_costcenter;
end;