Postgres VIEW-like behavior to simplify graph queries

Our postgres data source stores data within json blobs, and so the SQL necessary to extract what we want to visualize in Grafana is somewhat complex. We’d prefer not to have to duplicate that complexity in every graph.

What we want to be able to do is present the data to whoever is building the graphs in a simpler form - a simple tabular structure. This can be done in Postgres VIEWs, but we don’t want to bake these into the DB since they are specific to the Grafana work. (Also want to minimize direct DB access :wink:

Here is a simplified example of what we want to do:

DEFINE table_view AS (
SELECT
  json_blob->>time AS time,
  json_blob->some->deeply->nested->object->var AS var,
  ... etc
FROM
  table
)

So that then in a bunch of graphs we can just do:

SELECT
  time, var
FROM 
  table_view

Is there a way to replicate this type of behavior in Grafana - transforming the data into a simpler form? I see mentions of macros and templates and variables in the documentation, but none of those seem to create a reusable view of the data that can be shared between graphs.

There’s nothing in Grafana to help out with this. You could always put your views for grafana in a different schema.

Great - thanks for the follow up.

In other tools (PeriscopeData, etc), it is nice to have the ability to share macros/SQL snippets/etc between different graphs, to reduce the complexity of those charts. Would this be a useful feature to others?