title: Functions with variable number of input parameters
body: <p>I'm creating a stored procedure (function) in a PostgreSQL DB, which updates a table depending on its input. In order to create a variable number of parameter function, I'm creating an extra input parameter called mode, which I use to control which parameters I use on the update query.</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION update_site(
      mode integer,
      name character varying,
      city character varying,
      telephone integer,
  )
  RETURNS integer AS
  $$
  BEGIN
  IF mode = 0 THEN
  BEGIN
      UPDATE "Sites" SET 
      ("City","Telephone") = (city,telephone)
      WHERE "SiteName" = name;
      RETURN 1;
      EXCEPTION WHEN others THEN
      RAISE NOTICE 'Error on site update: %, %',SQLERRM,SQLSTATE;
      RETURN 0;
  END;
  ELSIF mode = 1 THEN
  BEGIN
      UPDATE "Sites" SET "City" = city
      WHERE "SiteName" = name;
      RETURN 1;
      EXCEPTION WHEN others THEN
      RAISE NOTICE 'Error on site update: %, %',SQLERRM,SQLSTATE;
      RETURN 0;
  END;
      ELSIF mode = 2 THEN
  BEGIN
      UPDATE "Sites" SET "Telephone" = telephone
      WHERE "SiteName" = name;
      RETURN 1;
      EXCEPTION WHEN others THEN
      RAISE NOTICE 'Error on site update: %, %',SQLERRM,SQLSTATE;
      RETURN 0;
  END;
      ELSE
              RAISE NOTICE 'Error on site update: %, %',SQLERRM,SQLSTATE;
      RETURN 0;
      END IF;
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>What would be best? To create a function <code>update_site(&lt;all the columns of table&gt;)</code> and a separate function <code>update_site(id integer, &lt;varchar column to update&gt;)</code>, or use the mode in one function to define the difference? Which option is more efficient? One unique function or different ones for each purpose?</p>