title: Postgres AVG function is not working with To_char function
body: <p>I am newbie in Postgres, I want to calculate the average 'duration' and converting it into a format like hh:mm:ss, in Postgres but when I am using the below query getting the error</p>
  <blockquote>
  <p>ERROR:  function avg(text) does not exist.</p>
  </blockquote>
  <p>HINT:  No function matches the given name and argument types. You might need to add explicit type casts.&quot;</p>
  <p>My query is</p>
  <pre><code>select processname, 
         count(processinstanceid), 
         avg(TO_CHAR((duration/1000 || 'seconds')::interval, 'HH24:MI:SS')) 
  from processinstancelog 
  group by processname 
  order by processname asc
  </code></pre>
  <p>However, the same function I am using to calculate the min and max
  'duration' and it's working. I have attached the screenshot as well.</p>
  <pre><code>select processname, 
         count(processinstanceid), min(TO_CHAR((duration/1000 || 'seconds')::interval, 'HH24:MI:SS')), 
         max(TO_CHAR((duration/1000 || 'seconds')::interval, 'HH24:MI:SS')),
  from processinstancelog
  group by processname
  order by processname asc
  </code></pre>
  <p><img src="https://i.stack.imgur.com/fMSKJ.png" alt="enter image description here" /></p>