Hello and thank you in advance! I am migrating my database from postgresql to mysql - and I am pretty unfamiliar with mysql at this point.

I have the following function in postgresql which I need to copy over to mysql, and I am hoping someone will be able to help me change the format to work in mysql.

Also, if you are familiar, I would like to change the output destination file to an ftp folder (which if it helps is located on the same server as the mysql database), if anyone knows how to do this, i would be appreciative.
Thank you. - Ryan

CREATE OR REPLACE FUNCTION get_unity_commissions() RETURNS bool AS $func$
    v_agent_name text;
   FOR v_agent_name IN SELECT DISTINCT agent FROM rdf_unity
       EXECUTE format($$COPY (
           SELECT "agent" "Agent",
	"group_name" AS "Plan Name",
	"month" AS "Month Paid",
	"rowlabels" AS "Subscriber",
	"sum_of_commission"* agent_rate AS "Commission",
	"values_sum_of_memb_count" AS "Member Count"
             FROM rdf_unity
             LEFT JOIN agent_commissions
             ON "agent" = agent_commissions.carrier_agent_name AND agent_commissions.carrier_name = 'Unity'
            WHERE agent = %s AND created_date = date(now())
           TO '/Users/ryanmoran/Downloads/SQLOutput/%s.%s.unity.csv'
           WITH CSV Delimiter ',' Header$$,
               replace(v_agent_name, ' ', '_'),
               to_char(now(), 'YYYY-DD-MM'));
    RETURN true;
$func$  LANGUAGE plpgsql;