I'm having trouble with this postgres function using a multi-valued (comma separated) parameter as a filter in my where clause using IN().
CREATE FUNCTION company_sites_report( company_list text )
RETURNS TABLE(company text, num_suppliers BIGINT)
LANGUAGE SQL
AS $$
SELECT company, count(supplier_id) num_suppliers
FROM MySitesTable
WHERE company IN ($1)
GROUP BY company;
$$;
So when I call the function:
SELECT *
FROM company_sites_report( 'Company1,Company2' );
It seems to treat the parameter value as one whole string and not split it into the particular strings (csv). How do I get it to behave as I need?