Help with Function AVG() PostgreSQL

I am trying to use the AVG function using PostgreSQL with a variable:

SELECT
AVG($field)

and receiving the error: ‘function avg (“unkown”) is not unique’

any help is much appreciated!

image

image

Can you show the generated SQL. There is a button below the query editor to show SQL sent to database.

The should work with some minor modification on recent grafana versions (5.0+). Grafana used to quote all variables as literals, but your variable is actually an identifier so it needs to be quoted differently. Postgres Datasource in Grafana 5 does not quote variables as literals anymore to allow for more flexibility in how variables can be used. In 5.0+ AVG("$field") should work for your case.

Thank you for your help! You are correct that we needed the latest version of Grafana.

I appreciate your support