Strange Transform Behavior on PostgreSQL Results

  • What Grafana version and what operating system are you using?
    Grafana v9.5.5

  • What are you trying to achieve?
    I have a panel with 3 PostgreSQL query results. I’ve aliased the results to “field1/2/3”. The queries are basically “select count(*) from table;”. I’m trying to sum the results of two queries. The panel type is “Stat”.

  • How are you trying to achieve it?
    Using a “Add field from calculation” transform with the Binary Operation mode. I also added a transform before this one to convert the fields on numeric format for good measure but disabling this doesn’t change the results.

  • What happened?
    Nothing happens when I select the two different fields on each side of the Operation. The transform only seems to work when I chose the SAME field on both sides of the operation.

  • What did you expect to happen?
    I expected the transform to work. I should see a new result that is the sum.

  • Can you copy/paste the configuration(s) that you are having problems with?
    No, it’s from my work install.

  • Did you receive any errors in the Grafana UI or in related logs? If so, please tell us exactly what they were.
    No errors.

  • Did you follow any online instructions? If so, what is the URL?
    I can’t find any similar issues.

I did change the query types to “random walk” and immediately this started working as expected. I’m guessing the issue is with my SQL results.

The below is my setup that isn’t working as expected.

This does work but only when I add a field value to itself.

I guess they have different timestamp. Check transformation debug option + browser console for errors.

I’m not sure what you mean by different time stamps. If I refresh, the obvious expectation is that in real time the number are updated and the transform is applied. That said, I’m not familiar with checking “transformation debug option”. Where can I find that info?

You are summing field1 and field3? Is that what you really wanted to do?

Otherwise i would recommend you do the sum in postgres query itself

Are the tables on the database?

Yes, I really want to sum them. … The results are actually from two separate database instances so I can’t do the sum in the SQL query.

1 Like

Are they on two separate servers?

Also on first picture we dont see the wrong result, what is it showing

Each of the 3 queries are coming from 3 separate databases. In the first image, the middle field is “field2” and the value of from the 2nd query, instead of using the configured alias “sum” and the sum’d value of fields 2 & 3, showing that the transform isn’t working unless I select the same query, “field”, for both sides of the operation.

Then dont use transform do it in one query

Please help me to understand how I’m not being clear. I can’t pull queries from 3 separate DBs / 3 separate datasources in one query right? And even if I can, all these questions seem to be missing my main point.

Grafana lets me take 2 numbers from two queries and add them together but it’s not working. It shouldn’t matter if this is from one DB, or one hundred, or anything else. It lets me add 2 numbers together and it doesn’t let me know any considerations as to why this might not work as expected. I feel like this is either a bug or really poor design. That said, if there is something I can do to work around the issue so it performs as expected, I’d like to know.

Yes you can even if they are on different servers (which you have not answered whether they are or not)

like this

Notice 1st my mssql data source (point at a database named grafana)

And here notice that same database along with a new one I created after you :wink:


And notice here, even though my main db connection is pointing to grafana I still have the option to query other databases on the same server

Then I do my query on cross databases

Final result

Lesson: avoid transformation cause you will hit a wall or they might not work on some data sources but this limitation might not documented, use grafana for what it does best, visualization, the rest try to do it in the data source itself if at all possible.

You only have one datasource there. I have 3 so that won’t work, but I do really appreciate the effort you went through to make your point.

I guess I’ll post in GitHub to see if the devs can fix this broken item.

are all datasources pointing to the same server? I think you are missing what I am trying to put down

it does not matter if you have a million data sources if they are all on the same server

3 separate hosts / URLs.

1 Like

My co-worker found a solution. He relayed “seems like data from the different datasources doesn’t have any common mapper or property. We can either go with add new mapper/property or ignore it.” I added the below above my “Add field from calculation” and it works now.

1 Like