How do I add COUNT values to a postgres table

I am trying to perform multiple COUNT queries and add the resulting values to a row in a postgres table. I’d also like the actual values so that I can visualize the results in a graph.

query1:

SELECT COUNT(column1)
FROM test_1

In a Retool table I can see a normal table by pulling the count data using:

{{query1.data}}

But when I try to append a row to a different table with the count results using {{query1.data}}, I end up with a resulting cell like this: “{“count”:[“3”]}”

Other things I have tried:
I’ve tried pulling the data from the Retool table that shows the count data as I expected using table1.selectedRow.data, which returns “{“count”:“3”}”, and table1.selectedRow.value, which returns “null”.

Any thoughts on how to just get the numerical count value?

Postgres will automatically assign a column name to the result. I prefer to set it directly as in:

SELECT COUNT(column1) as my_count
FROM test_1 

Then you can refer to it in Retool from the data array:

{{query1.data.my_count}}

Sometimes need to do this:

{{query1.data.my_count[0]}}

1 Like

This is what I was looking for! I’m getting the numerical count values when I add rows to the new table, and the graphs are showing the values as well.

Thanks!