title: Position of the lowest value greater than x in ordered postgresql array (optimization)
body: <p>Looking at the postgres function array_position(anyarray, anyelement [, int])</p>
  <p>My problem is similar, but I'm looking for the position of the first value in an array that is greater than an element. I'm running this on small arrays, but really large tables.</p>
  <p>This works:</p>
  <pre><code>CREATE OR REPLACE FUNCTION arr_pos_min(anyarray,real)
    RETURNS int LANGUAGE sql IMMUTABLE PARALLEL SAFE AS
  'select array_position($1,(SELECT min(i) FROM unnest($1) i where i&gt;$2))';
  </code></pre>
  <p>the array_position takes advantage of the fact that my array is ordered, but the second part doesn't. And I feel like the second part could potentially just return the position without having to re-query.</p>
  <p>My arrays are only 100 elements long, but I have to run this millions of times and so looking for a performance pickup.</p>
  <p>Suggestions appreciated.</p>