Ivanka Todorova Ivanka Todorova - 1 year ago 91
MySQL Question

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

I'm using Laravel and have a query that selects using

of a column:

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

I have installed mysqldn and AFAIK Laravel uses

is a string, no matter what type of the column is. (It's an integer column)

Also if I do:

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

is returned as an integer.

Answer Source

It's neither Laravel or PDO issue.

According to manual, SUM() returns a DECIMAL value for exact-value arguments (integer or DECIMAL). And the only way to represent DECIMAL type in PHP is string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download