title: Create function with SELECT CASE
body: <p>I want create a function with 2 parameters. This is my <code>SELECT</code> statement: </p>
  
  <pre><code>SELECT CASE 
     WHEN duration &lt;=  10000000 THEN '00-01 sec'
             WHEN duration &lt;=  40000000 THEN '01-04 sec' 
             WHEN duration &lt;= 100000000 THEN '04-10 sec' 
             WHEN duration &lt;= 300000000 THEN '10-30 sec' 
             WHEN duration &lt;= 600000000 THEN '30-60 sec' 
             ELSE 'more than 60 sec' END AS "Kategorien", 
     COUNT(*) AS Requestcounter
  FROM tablename
  WHERE starttime BETWEEN '2016-03-01 00:00:00' AND '2016-03-08 14:00:00'
  GROUP BY
    (CASE WHEN duration &lt;=  10000000 THEN '00-01 sec'
     WHEN duration &lt;=  40000000 THEN '01-04 sec' 
     ELSE 'more than 60 sec' END); 
  </code></pre>
  
  <p>Result: </p>
  
  <pre><code> Kategorien | requestcounter
  ------------+----------------
   00-01 sec  |           2073
   01-04 sec  |              2
  (2 rows)
  </code></pre>
  
  <p>I want this result from my function. But I get the error: </p>
  
  <blockquote>
    <p>query has no destination for result data</p>
  </blockquote>
  
  <p>This is my function:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION requestcounter(mindate timestamptz,maxdate timestamptz) 
  RETURNS SETOF integer AS $$ 
  
  BEGIN
  SELECT CASE WHEN duration &lt;=  10000000 THEN '00-01 sec'
              WHEN duration &lt;=  40000000 THEN '01-04 sec'  
              ELSE 'more than 60 sec' END AS "Kategorien", 
  COUNT(*) AS Requestcounter from tablename where starttime BETWEEN mindate and maxdate
  GROUP BY
    (CASE WHEN duration &lt;=  10000000 THEN '00-01 sec' 
          WHEN duration &lt;=  40000000 THEN '01-04 sec'  
          ELSE 'more than 60 sec' END);
  Return; 
  END;
  $$ LANGUAGE plpgsql;
  </code></pre>
  
  <p>I know that <code>RETURNS SETOF integer</code> is not right but I have no idea how to get this to work?</p>