Postgres' bigint type holds 64 bit integers. But the Supabase JS library returns those values as JS numbers, which cannot safely store 64 bit integers AFAIK. What would be the correct way to handle 64 bit integers in Supabase?
-
1Store it as a string?– Dane BrouwerNov 23, 2022 at 15:31
-
@DaneBrouwer Are you telling me to store it as a string in Postgres? But using a bigint would be a lot more performant than using strings right? I plan to use that column as the primary key too.– Sumit GhoshNov 23, 2022 at 15:45
Add a comment
|
1 Answer
You are correct. This is because numbers in JS are float64, so if your number is more than Number.MAX_SAFE_INTEGER === 9007199254740991
. It won't be represented correctly.
An alternative is to cast it to text during the call & manually convert it:
supabase.from('table_name').select('id, num::text');
BigInt(data);