Why does SUM (`column`) return a string instead of an integer?

I use Laravel and have a query that selects using a DB::raw() SUM()column:

DB::raw("SUM(points) as game_points")

I installed mysqldn and AFAIK Laravel uses PDO.

But game_points- this is a row, regardless of the type of column. (This is an integer column)

Also, if:

DB::raw("COUNT(id) as foo_bar")

foo_bar is returned as an integer.

+4
source share
2 answers

This is not a Laravel or PDO issue.

, SUM() DECIMAL (integer DECIMAL). DECIMAL PHP .

+6

CONVERT(INT, game_points)

bugs.mysql.com, sum() NEWDECIMAL, string php, count() integer.

-3