0

In MySQL, it's because SUM() returns a DECIMAL. From PostgreSQL docs:

sum(smallint) → bigint  
sum(integer) → bigint  
sum(bigint) → numeric  
sum(numeric) → numeric  
sum(real) → real  
sum(double precision) → double precision  
sum(interval) → interval  
sum(money) → money
     Computes the sum of the non-null input values.

Since I'm calculating the sum of integers, therefore it should return an integer?

1 Answer 1

4

Postgres' bigint is up to 264 which is larger than JavaScript's Number.MAX_SAFE_INTEGER (253), therefore it's usually represented with string.

We can use JS' parseInt() or cast bigint to integer directly:

SELECT CAST(SUM(salary) as INTEGER)
FROM employee;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.