I’m using Grafana v13.0.1 on docker. I’m trying to create shared dashboard with panel using variables inside query. I’ve added variable to dashboard. Then I’ve created simple panel with postgresql query “select $var as variable”.
Inside grafana it works as expected. When I open dashboard from shared dashboard link I get "db query error: ERROR: syntax error at or near “$” (SQLSTATE 42601)
When I look at database logs everything is fine, received query contains actual value of variable, instead of “$var” text. Data is being send back to grafana as usual. I’ve tried different databases and everywhere it’s the same.
Welcome to forum. Try
select ‘$var’ as variable
Hi,
This is a known Grafana variable interpolation behavior, especially noticeable in shared dashboards.
What’s happening here is that in the shared dashboard context , Grafana sometimes evaluates the panel differently (especially for SQL-based datasources like PostgreSQL). Instead of properly substituting $var , it’s ending up sending the raw query string to the database, which is why PostgreSQL throws:
syntax error at or near "$"
Even though your logs sometimes show the final value, the issue usually comes down to when/where the variable is expanded in the request pipeline .
A few things to check/workaround:
- Try using the bracket syntax instead of
$var
→ ${var} or ${var:raw} depending on your use case
- Ensure the variable is set as Query type / Custom type correctly , and marked as “Include All option” off if not needed
- Test using URL-encoded shared link vs snapshot link (they behave differently in variable resolution)
- Check if template variable caching is enabled in Grafana 13 shared links
- As a workaround, try forcing interpolation in SQL safely, e.g.:
select '${var}' as variable
(only if the value is trusted / controlled)
This issue is fairly common with shared dashboards because Grafana sometimes resolves variables in the UI layer but not consistently in exported/shared contexts.
If you want, I can help you adjust the exact query pattern based on your variable type (query, custom, or interval).
Unfortunatelly no luck. Putting variable in {} brackets and adding :raw doesn’t change anything. Even using '${var}' just returns ${var} text in shared dashboard.
I’ve tried simple select 1 query and custom 1, 2, 3 variable. Nothing changes.
Snapshot link works, but well it’s snapshot.
I guess I will just give up
. It’s not that important.