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?
How to use bigint safely with Supabase JS
Asked Answered
Store it as a string? –
Needle
@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. –
Chemical
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);
© 2022 - 2024 — McMap. All rights reserved.