I have a simple query below :
CREATE OR REPLACE FUNCTION companies_all_teams( IN _company_name text = NULL, IN _company_id int = NULL, OUT _result text ) AS $$ BEGIN _result := (SELECT json_agg(distinct(teams.name)) FROM jobs JOIN companies ON companies.id = jobs.company_id JOIN teams ON teams.id = jobs.team_id WHERE lower(companies.name) = lower(_company_name) AND jobs.is_disabled = false ); END;
CREATE OR REPLACE FUNCTION companies_all_teams( IN _company_name text = NULL, IN _company_id int = NULL, OUT _result text ) AS $$ BEGIN _result := (SELECT json_agg(distinct(teams.name)) FROM jobs JOIN companies ON companies.id = jobs.company_id JOIN teams ON teams.id = jobs.team_id WHERE lower(companies.name) = lower(_company_name) AND jobs.is_disabled = false ); END;
$$ LANGUAGE plpgsql;
There are two inputs, but only one of those is being used in the query. What is the simplest way that we can doto run the query conditionally based on which input we have ?
Thanks