title: PostgreSQL function with select returning one value
body: <p>I have a table <code>years</code> (jan 1st of each ear). I want to create a function that takes each of those years and runs a query on another table to count the number of rows that belonging to that year. I tried to implement with pl/pgsql, using the code bellow, but I'm not getting it to work or finding any reference on the Internet.</p>
  
  <pre><code>CREATE or REPLACE FUNCTION func_test(in AAA date, OUT _result int) 
  BEGIN
     SELECT SUM(st_length(geom)) as BBB
     FROM hist_line
     WHERE '2006-01-01' BETWEEN valid_from AND COALESCE(valid_to, '9999-12-31');
     RETURN _result BBB;
  END;
  $$ LANGUAGE plpgsql;
  CREATE or REPLACE FUNCTION func_test(date) 
  
  select func_test('2009-01-01');
  </code></pre>
  
  <p>I'm not able to recover the content query inside the function as the output of the function.</p>