Mysql Split by ZERO, SQL_MODE = 'TRADITIONAL'?

Asked

Viewed 349 times

2

I’m with the SQL_MODE of MySQL as TRADITIONAL in the version is 5.7.18 and according to the documentation this way would make the MySQL operate in the same way as other banks, for example SQL Server.

But when I do:

select 651/0;

instead of accusing the division error by zero (Divide by zero error encountered.) it gives the result as null.

Does anyone know how to solve?

Documentation:

TRADITIONAL

Make Mysql behave like a "Traditional" SQL database system. A simple Description of this mode is "Give an error Instead of a Warning" when inserting an incorrect value into a column. It is one of the special Combination modes Listed at the end of this Section.

Note The INSERT or UPDATE aborts as soon as the error is noticed. This may not be what you want if you are using a nontransactional Storage engine, because data changes made prior to the error may not be Rolled back, Resulting in a "partially done" update.

1 answer

0

EDIT

According to the documentation that can be accessed at this link, division by zero does not return error for a command SELECT.

For SELECT, Division by zero Returns NULL. Enabling ERROR_FOR_DIVISION_BY_ZERO causes a Warning to be produced as well, regardless of whether Strict mode is enabled.

In operations of the type INSERT and UPDATE work normally. In the same documentation it is quoted that the mode ERROR_FOR_DIVISION_BY_ZERO is deprecated and will be removed as a separate module name.

  • I think what the questioner wants is for an error to be reported and not to treat NULL improperly returned.

  • Thank you for signaling the inconsistency. I performed the adjustment to better fit the question raised.

Browser other questions tagged

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