Changing the Mysql version

Asked

Viewed 116 times

0

I have this table in Mysql called logou:

id | idconta | dia

This query in Mysql always worked on my server:

SELECT dia FROM logou GROUP BY YEAR(dia), MONTH(dia) ORDER BY dia DESC

But now that the system has gone to the client server, and everything indicates that it is another version of Mysql or a SQL Server (can it be? Client is from Belgium, and are VERY boring in talking details of their server), this query presents this error:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'eusoucomp-br-qa.logou.dia' which is not functionally dependent on Columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

What can it be? And how to fix?

  • you have access to the bank ?

  • @Marconciliosouza no... This is rpoblema, just send the files to them, and 10 days later they put on air.

1 answer

1


Starting with Mysql 5.7 the default behavior of Mysql has been modified and the mode ONLY_FULL_GROUP_BY inserted by default. If you do:

mysql> SET sql_mode = '';

And it will be possible to run the query without errors (but you will need to do it every session).

The best solution is to do something like this using the ANY_VALUE function():

SELECT ANY_VALUE(dia) as dia FROM logou group by year(dia), month(dia) ORDER BY dia DESC;

I did the tests here using version 5.7.21-0ubuntu0.17.10.1 and, interestingly, in version 10.1.30-0ubuntu0.17.10.1 of Mariadb this problem does not even occur.

  • Hi, where would I put this line? mysql> SET sql_mode = '; In the database connection file?

  • If you change the query and use ANY_VALUE() you do not need to touch sql_mode (for your question, you do not have access to the server). To change this setting look for Mysql configuration files in "/etc/mysql/mysql.conf. d/mysqld.cnf" or "/etc/mysql/my.cnf", there will be a part of the file identified as [mysqld] and there should be the sql_mode line, remove only the ONLY_FUL_GROUP_BY from there and restart the service.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.