Hi guys,
I'm writing a simple Plpgsql function to delete some data from different tables.
The function starts with a select, and then 2 deletes after that.
How can I return the number of rows that each delete performed?
CREATE or REPLACE FUNCTION delete_ids_clientid(account_id integer)RETURNS integer AS $$declarerow record;account_id integer;BEGINFOR row IN EXECUTE 'SELECTFROMpublic.table2 t2JOINWHEREt2.account_id = ' || account_id || ''LOOPDELETE FROM public.table1 WHERE id IN(SELECTidFROMpublic.table1 t1WHERE);DELETE FROM public.table2 WHERE billable_id IN(SELECTbillable_idFROMpublic.table2 t1WHERE);END LOOP;END$$ language 'plpgsql';
Cheers