timeFilter generating different timestamps in alert compared to dashboard

The SQL generated on a dashboard panel:

SELECT
  timestamp AS "time",
  id AS id,
  cast(value as double) AS "value",
  key
FROM 'gvo-logging'
WHERE key = 'System/Memory Usage' AND timestamp BETWEEN '2022-05-24T13:10:39.428Z' AND '2022-05-24T14:10:39.428Z'

executes fine on QuestDB over PSQL

When using the same SQL in an alert rule, the granularity of the timeFilter is much greater, and causes the query to fail:

SELECT
  timestamp AS "time",
  id AS id,
  cast(value as double) AS "value",
  key
FROM 'gvo-logging'
WHERE key = 'System/Memory Usage' AND timestamp BETWEEN '2022-05-24T14:05:58.160103525Z' AND '2022-05-24T14:10:58.160103525Z'

SQL used in alert query:

SELECT
  timestamp AS "time",
  id AS id,
  cast(value as double) AS "value",
  key
FROM 'gvo-logging'
WHERE key = 'System/Memory Usage' AND $__timeFilter(timestamp)

Grafana v8.5.1 (61fe4a1859)

what is the setting on your timepicker? can you share a few screenshots?

Hi there, did you find a solution to this?

I’ve had similar issues querying questdb from alerts using the postgres datasource.

See Alert Query Not working with global variables

I’ve tried to control the format of the datetime generated but I still get an invalid date error.

AND ts BETWEEN ‘${__from:date:YYYY-MM-DDTHH:mm:ss.sssZ}’ AND ‘${__to:date:YYYY-MM-DDTHH:mm:ss.sssZ}’

When I inspect the query or add the query to a panel it runs successfully.

Would be grateful for any help, or hints.

Can you reply to the question posted 5 days ago on the original thread that you linked to?

1 Like