title: How to use mixed int and numeric arguments in a Postgres 9.1+ function
body: <p>I'm looking for a way to create an <code>icase()</code> function which works with any second and third parameter compatible data types.<br>
  I tried in Postgres 9.4:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.icase(
      cond1 boolean,
      res1 anyelement,
      conddefault anyelement)
    RETURNS anyelement AS
  ' SELECT CASE WHEN $1 THEN $2 ELSE $3 END; '
    LANGUAGE sql IMMUTABLE;
  </code></pre>
  
  <p>But:</p>
  
  <pre><code>select icase( true, 1.0, 0 )
  </code></pre>
  
  <p>causes error:</p>
  
  <blockquote>
  <pre><code>ERROR:  function icase(boolean, numeric, integer) does not exist
  LINE 9: select icase( true, 1.0, 0 )
                 ^
  HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
  </code></pre>
  </blockquote>
  
  <p>How to fix this in 9.1+ so that second and third arguments can be either int or numeric?</p>
  
  <p>This method may be called if both second and third parameters are <code>text</code>, <code>char(n)</code>, <code>date</code>, <code>numeric</code> or <code>int</code> types.</p>