I’m trying to query from a Postgres table and display resulting metrics in a Graph panel.
The Postgres table has log entries with two date columns per row: CreationDate
and LastLogDate
. CreationDate
always has the first logged date, and LastLogDate
has the date of the last occurrence of the same log type.
With the Grafana query builder, I get the following query:
SELECT
$__timeGroupAlias("CreationDate",$__interval,NULL),
"ApplicationName" AS metric,
max("DuplicateCount")
FROM "Errors"
WHERE
$__timeFilter("CreationDate")
GROUP BY 1,2
ORDER BY 1,2
It works fine, except that I want to group & filter by LastLogDate
if it’s not null, instead of CreationDate
, but I’m not sure how to specify a coalesce (take first non-null value) function along with $__timeGroupAlias
and $__timeFilter
functions. It this possible somehow?