How to use global variables in PostgresSQL query?

Hello everyone!

Using: Grafana Cloud
Datasource: PostgresSQL v. 14+ (supabase io)

I am trying to query data based on dashboards time range with $__from and $__to global variables (docs here).

This is the query I wrote for timeseries chart:

SELECT
  "timestamp" AS "time",
  etalon,
  humidity,
  temperature
FROM "values"
WHERE
  $__timeFilter("timestamp") 
  and "timestamp" >= {$__from:date}
  and "timestamp" <  {$__to:date}
ORDER BY 1

This results in:
image

I have also tried:

  1. Removing the curly brackets {} = results in syntax error near ":"
  2. Using just $__from without the :date keyword = results in: db query error: pq: operator does not exist: timestamp with time zone >= bigint

If anyone would have any suggestion I would be so grateful!

I managed to get something working but still can’t translate the BIGINT to DATE TIME with timestamp.

This is my query now:

SELECT
  "timestamp" AS "time",
  etalon,
  humidity,
  temperature,
  $__to as to,
  $__from as from,
  ${__to.date} as to_date,
  ${__to.date.iso} as to_date_iso
FROM "values"
WHERE
  $__timeFilter("timestamp")
ORDER BY 1

This is the result: