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
Code:
CREATE OR REPLACE FUNCTION get_unity_commissions() RETURNS bool AS $func$
DECLARE
v_agent_name text;
BEGIN
FOR v_agent_name IN SELECT DISTINCT agent FROM rdf_unity
LOOP
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$$,
quote_nullable(v_agent_name),
replace(v_agent_name, ' ', '_'),
to_char(now(), 'YYYY-DD-MM'));
END LOOP;
RETURN true;
END;
$func$ LANGUAGE plpgsql;