title: Postgres resampling time series data
body: <p>I have OHLCV data of stocks stored in 1-minute increments inside Postgres.</p>
  
  <p>I am trying to resample data to 5 minutes interval. I have used this <a href="https://stackoverflow.com/a/27631673/5970352">answer</a> to generate the following SQL query.</p>
  
  <p>Here is the SQL query generated:</p>
  
  <pre><code>SELECT 
  avg('open') AS open, 
  avg('high') AS high, 
  avg('low') AS low, 
  avg('close') AS close, 
  avg('volume') AS volume, 
  avg('open_interest') AS open_interest, 
  to_timestamp(floor(EXTRACT(epoch FROM 'timestamp') / 300) * 300) AS interval_alias 
  WHERE 'symbol'='IRFC-N8' GROUP BY interval_alias
  </code></pre>
  
  <p>I am getting this error:</p>
  
  <pre><code>sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) function avg(unknown) is not unique
  LINE 1: SELECT avg('open') AS open, avg('high') AS high, avg('low') ...
                 ^
  HINT:  Could not choose a best candidate function. You might need to add explicit type casts.
  </code></pre>
  
  <p>Could you tell me what went wrong?</p>
  
  <p><strong>Edit 1</strong>: Code formatted for better rendering.</p>
  
  <p><strong>Edit 2</strong>: According to the answer below, I need to use double quotes around the parameter to the avg function. I am using sqlalchemy to generate the expressions and it is creating single quoted strings. Here is the part of code which generates the avg query:</p>
  
  <pre><code>    cols = list()
      cols.append(func.avg(self.p.open).label(self.p.open))
      cols.append(func.avg(self.p.high).label(self.p.high))
      cols.append(func.avg(self.p.low).label(self.p.low))
      cols.append(func.avg(self.p.close).label(self.p.close))
      cols.append(func.avg(self.p.volume).label(self.p.volume))
      cols.append(func.avg(self.p.openinterest).label(self.p.openinterest))
      seconds = self._get_seconds()
      cols.append(func.to_timestamp(func.floor(func.extract("epoch", "timestamp") / seconds) * seconds).label("interval_alias"))
  </code></pre>
  
  <p>SqlAlchemy should have known better to use double quotes but its generating single quotes.</p>