Retool treats Postgres some numeric types as strings

Postgres queries that return values of type bigint, decimal, and numeric are being treated as strings by Retool. I understand the technical reasons for this: Javascript cannot represent the largest bigint values or the precision of decimal. However, I believe that for 99.99% of users and use cases, it would be better to convert the value to a Javascript number and warn if the value was truncated.

select count(*), avg(tally) from records;

The count() aggregate function returns bigint, and avg() returns numeric for integer arguments. If you try to display these using the Statistic component it shows an error, because the input is a string, not a number. I can manually cast these to other types (integer or double precision) either in the query or using parseFloat, but that is rather cumbersome.

Thank you for the great product!

1 Like

Hey @trevorlynnsmith, and welcome to the community! Apologies for the delay, the Retool team has been enjoying a few days off :slight_smile:

You are correct! Retool does coerce numbers to strings in a lot of cases like these. I think you definitely make a good point and I’ll share it with the rest of the team!

Following up with some more info — when we serialize bigints, numeric, and decimal data types to JSON, we cast them to strings to avoid loss in precision.

We do want to be careful that we don’t break existing apps that might rely on the current behavior. I think that adding an option to parse all number types into JS Numbers is a reasonable path forward to maintain back-compat, but we’ll need to do a little thinking on where to put this option.

We don’t have a timeline for this, but thanks for flagging this as an area of improvement! We might pick this up in an upcoming hackweek soon :slight_smile:

I appreciate the consideration and the helpful response! I’ll keep an eye out for it in the future.