SQL COUNT is a string instead of an integer

Hello everyone,

I’m trying out the SQL + Chart template with my own database, but for some reason my COUNT column is a string instead of an integer, so the numbers in the y axis are all out of order…or rather in string sorted order which isn’t what I was hoping for.
My query is similar to this:

SELECT year, COUNT(*)
FROM table
GROUP BY year;

Not sure what I did wrong because when I run this in pgAdmin, COUNT is a bigint.

Try:

SELECT year, COUNT(*)::INT
FROM table
GROUP BY year;
1 Like

JavaScript’s support for bigint is relatively recent, so we still map the bigint database type to strings rather than numbers to avoid possible loss of precision. In the future we may enable bigint support for database clients.

1 Like

@Cobus ’ solution worked for me since my count values aren’t extremely large.
@mbostock bigint support in the future would be wonderful!

Thank you both for your replies!