PostgreSQL query returns integer values as strings

I have a query that looks like this:

SELECT SUM(count) as rq
FROM usage_ip ...

The data it returns looks like this:

CleanShot 2023-03-11 at 17.26.52@2x

Why are integers strings? I can't do _.sum() on them, for example.

When I run the same query in the database (outside of Retool), these are integer values.

Hey @erusev, welcome to the community :hugs:

Seems like you have mixed data types for that column. If the input values are of a mixed data type, the result will be of the higher data type.

But you can cast to INT for _.sum() to work

SELECT
  CAST(SUM(count) AS INTEGER) AS rq
FROM 
  usage_ip

:v:

2 Likes

Nice! It works when I cast to INT :star_struck:

I don't get it though -- that column is an integer (int2), and all values in it are integers -- where are the mixed data types coming from :thinking: