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?

M Imam Pratama
  • 998
  • 11
  • 26

1 Answers1

2

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;
M Imam Pratama
  • 998
  • 11
  • 26