title: Use SQL query as array parameter (input) in custom function
body: <p>I created a custom function in pl/pgsql and it's only input is an array. I would like to use the result of a query as the input for this custom function, but can't seem to get it right. I'll use a simpler function as an example and also a simpler query than the one I'm trying to use as input.</p>
  
  <p>Function definition:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION bigger_than_ones(input_array int[])
  returns SETOF int
  AS
  $$
  DECLARE
    array_item int;
  BEGIN
    FOREACH array_item in ARRAY input_array
    LOOP
      IF array_item &gt; 1 THEN
        RETURN NEXT array_item;
      END IF;
    END LOOP;
  END
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>I have a table that has a column the same datatype of the array datatype. In this case an integer column:</p>
  
  <pre><code>SELECT * FROM my_table;
  id | int_attribute
  ---+--------------
  1  | 2
  2  | 3
  3  | 1
  4  | 4
  5  | 1
  6  | 6
  7  | 1
  8  | 1
  9  | 8
  </code></pre>
  
  <p>I would like to use a query that returns a column of that datatype as the input for my function. I've tried a few variations of this, without any luck:</p>
  
  <pre><code>SELECT * FROM bigger_than_ones(SELECT int_attribute FROM my_table);
  </code></pre>
  
  <p>To return:</p>
  
  <pre><code>result 
  -------------
  2
  3
  4
  6
  8
  </code></pre>
  
  <p>The reason I'm using a similarly structured function is because I need to calculate resulting merged time ranges (custom type) from multiple tables, in multiple places in my code. My best thought was to create a function that would do that, using as input all the time ranges, regardless of where I took it from, so I wouldn't have to make a more complex query each time.</p>
  
  <p>Any thoughts on what I'm missing?</p>