[php-src] Issue #14918: pdo_mysql not returning int for `sum` aggregate function
| From: | SamMousa | Date: | Thu, 11 Jul 2024 12:37:06 +0000 |
| Subject: | [php-src] Issue #14918: pdo_mysql not returning int for `sum` aggregate function | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247274@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/14918
Author: SamMousa
### Description
The following code:
```php
<?php
var_dump($db->pdo->query(<<<SQL
select sum(
id), avg(id), json_type(sum(id)) from
(
select 1 as id
union
select 2 as id
) as sub
SQL, \PDO::FETCH_ASSOC)->fetch());
```
Resulted in this output:
```
array(3) {
'sum(id)' =>
string(1) "3"
'avg(id)' =>
string(6) "1.5000"
'json_type(sum(id))' =>
string(7) "INTEGER"
}
```
But I expected this output instead:
```
array(6) {
'sum(id)' =>
int(3)
'avg(id)' =>
float(1.5)
'json_array(sum(id))' =>
int(3)
'json_type(sum(id))' =>
string(7) "INTEGER"
}
```
It seems the sum function does not result in a properly typed value. Upon further
investigation:
- avg also exhibits this behavior
- I added a json_type column (which could be mariadb only) to see what the database
engine thinks of the type
- tested on version 8.3.? as well with mysql
### PHP Version
8.2.20
### Operating System
docker(alpine)