-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pdo_mysql not returning int for sum
aggregate function
#14918
Comments
Are you using the |
I'm not, I should have included that explicitly in my test case. I noticed it in an result set where half of my fields were proper |
Okay, it's just to be sure that the attribute is not the reason. :) |
Another test case that illustrates that <?php
var_dump($db->pdo->query(<<<SQL
select min(`id`), 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());
|
Thing is that SUM and AVG both return either DECIMAL- or DOUBLE-typed values, depending on the arguments. Either way means it's not a plain integer. So I think this is working correctly... |
What is the var type if exec the following query?
Will it be an int? edit: If integer types are also retrieved as strings, we recommend checking if the driver you are using is mysqlnd (you can check this with phpinfo). |
These are ints.
This is not the case as in my previous message I already showed that a
How could we confirm this? If I look for "formal" docs on
Some more testing shows that |
MariaDB's docs don't say anything about return types, at least that I could see, but MySQL's does:
When the function returns a DECIMAL then I would expect to see a string in PHP, and when the function returns a plain integer-type then I would expect to see an integer. |
Yeah I agree; but this is inconsistent with how they deal with |
|
Description
The following code:
Resulted in this output:
But I expected this output instead:
It seems the
sum
function does not result in a properly typed value. Upon further investigation:avg
also exhibits this behaviorjson_type
column (which could be mariadb only) to see what the database engine thinks of the typePHP Version
8.2.20
Operating System
docker(alpine)
The text was updated successfully, but these errors were encountered: