(PostgreSQL, Node.js & Discord.js) . Why is my query output showing something completely different than what it is in the database?

Solution for (PostgreSQL, Node.js & Discord.js) . Why is my query output showing something completely different than what it is in the database?
is Given Below:

The issue (in more detail): I am new to PostgreSQL and I was running a query in Postbird which just created a table with a bunch of values:

CREATE TABLE guild_settings (
  mute_role_id bigint,
  guild_id bigint,
  member_role_id bigint,
  mod_log bigint,
  member_log bigint
);

I inserted a value as a test into the column guild_id in PostBird using the “Query” Feature:

INSERT INTO guild_settings (guild_id) VALUES (843893421277446185);

Now, I come into my code editor and I run the code (in an async function run as a command):

const res = await sql `select * from guild_settings`;
console.log(res)

When I run the command above I get this:

[
  {
    mute_role_id: null,
    guild_id: 843893421277446100,
    member_role_id: null,
    mod_log: null,
    member_log: null
  },
  count: 1,
  command: 'SELECT'
]

As you may tell, the last 3 digits are different than the one I inputted.

Why is the guild_id showing 843893421277446100 when I very clearly made it 843893421277446185? I deleted the table, went to a different database, I tried everything, but nothing seemed to work. I also scoured the internet for answers but I couldn’t find anything.

Code:

sql.begin(async sql => {
            const [res] = await sql`
            select guild_id from guild_settings
            `
            console.log([res])
        }).catch(err => console.log(err + "Something went wrong."))

Below are some images below of what the database shows as opposed to what the console shows and the query I made.

The Insert Query

The Database Content

The Console

The problem is that while PostgreSQL can store numbers up to 9,223,372,036,854,775,807 (2^63-1) as a bigint, in JavaScript the MAX_SAFE_INTEGER is 9,007,199,254,740,991 (2^53-1). Anything above that number is, well, unsafe and JavaScript has difficulty interpreting it.

In your case the last two digits become zero:

Max safe integer9007199254740991
Your integer843893421277446185
Your integer becomes843893421277446100

That’s why the Snowflake IDs are returned as string in the Discord HTTP API (to prevent integer overflows in some languages).

Your solution would be to either store snowflake IDs as strings or instead of the postgres npm package use node-postgres. As far as I know it returns the correct value for bigints (as JS also supports this data type now).