Postgres Function Slower than Query / Postgres 8.4
<p>I (must) use a Postgres 8.4 Database. In this Database i create a function:</p>

<pre><code>CREATE OR REPLACE FUNCTION counter (mindate timestamptz,maxdate timestamptz) RETURNS integer AS $func$ 
DECLARE result integer; 
BEGIN
Select INTO result COUNT(*) AS counter from columname where starttime BETWEEN $1 and $2;
Return result;  
END
$func$ LANGUAGE plpgsql;
</code></pre>

<p>The Query: </p>

<pre><code>apptelemetry=# select counter('2016-03-01 00:00:00','2016-03-11 00:00:00');
 requestcounter
----------------
           8893
(1 row)

Time: 4.740 ms
</code></pre>

<p>When i make a normal Query:</p>

<pre><code>apptelemetry=# select Count(*) from columname where starttime BETWEEN '2016-03-01 00:00:00' AND '2016-03-11 00:00:00';
 count
-------
  8893
(1 row)

Time: 3.214 ms
</code></pre>

<p>Why is the function slower than the normal query? Have someone performance tips for me? </p>

<p>Regrads</p>