PostgreSQL INNER JOIN Query

Grafana v8.0.6
PostgreSQL 13

I am attempting to set up graphs from data contained in the DB tables using INNER JOIN. The query I have started with in pgAdmin 4 retrieves exactly what I am looking for. See snippet below. This is the query i am running in the query tool.

Working PostgreSQL Query:

SELECT
tm.source,
td.value,
td.timestamp
FROM
trend_view td
INNER JOIN trend_meta tm
ON td.externallogid = tm.externallogid
WHERE
tm.source like ‘%PRTG%AC8%’ AND
td.type = 0
ORDER BY
tm.source;

I’ve attempted to transpose this as best I can into a Time Series chart and struggling to get any data back at all.

Here is what I used in Grafana with the text editor:

SELECT
v.timestamp AS “time”,
m.source AS “metric”,
v.value AS “value”
FROM trend_view v
INNER JOIN trend_meta m
ON m.externallogid = v.externallogid
WHERE
m.source like ‘%PRTG%AC8%’ AND
v.type = 0 AND
$__timeFilter(edittime)
ORDER BY v.timestamp;

Any input I can get here would be super awesome!

I suggest you build view of this query without WHERE clause to join the tables, then query the view from Grafana using WHERE clause that you needed.
It’s make easier to query and control the result.

Regards,
Fadjar Tandabawana

1 Like

This topic was automatically closed after 365 days. New replies are no longer allowed.