supabase / postgrest-js

Isomorphic JavaScript client for PostgREST.
https://supabase.com
MIT License
965 stars 129 forks source link

supabase javascript lib returns incorrect numeric value for bigint column #419

Closed andyk closed 1 year ago

andyk commented 1 year ago

Bug report

Describe the bug

The value returned by the javascript supabase lib for a column of type bigint is wrong for large integer values. It seems to be rounded. Maybe because of overflow in javascript's numeric type.

Maybe related to supabase/supabase#13612.

Here is my code in my Create React App:

        supabase.from('NewThoughts').select('*').then(response => {
            console.log("THOUGHTS:");
            console.log(response.data);
        });

(screenshot of code)

Here is the result in my browser console:

image

Here is my table in supabase

image

But if (per the advice in this stackoverflow post) i change the code to:

        supabase.from('NewThoughts').select('id::text').then(response => {
            console.log("THOUGHTS:");
            console.log(response.data);
        });

the values returned from the lib seems correct

image

Env

Additional context

> npm list
headlong@0.1.0 /Users/andyk/Development/headlong/frontend
├── @emotion/react@11.10.6
├── @emotion/styled@11.10.6
├── @mui/material@5.11.16
├── @mui/styled-engine-sc@5.11.11
├── @supabase/supabase-js@2.15.0
├── axios@0.19.2
├── cra-build-watch@1.4.1
├── react-scripts@5.0.1
├── react-window@1.8.8
├── socket.io-client@4.6.1
└── styled-components@5.3.9

> npm --version
9.6.2
> node --version
v19.8.1
GaryAustin1 commented 1 year ago

JavaScript does not support bigint. You can cast to a string.
supabase.from('table_name').select('id, num::text');

andyk commented 1 year ago

Makes sense. Could the lib check the column type and throw an error instead of returning incorrect values?

soedirgo commented 1 year ago

Thanks @andyk - let's track this on https://github.com/supabase/postgrest-js/issues/319.

andyk commented 1 year ago

Sounds great