0

Im trying to get eeror about invalid data for a query but it seems mysql accept strings as tiney in queries and set 0 instead of returning any error.

So how can I restrict it to just accept integers.

Thanks in advance.

1
  • Mysql will take leading integers in a string and discard the rest - this is documented behaviour, if you want to prevent it catch in your front end or in a trigger. Commented Jan 26, 2021 at 11:32

1 Answer 1

1

This is SQL Mode-dependent.

In strict mode you must receive either 'Data truncated' (inserted value starts from numeric chars) or 'Incorrect integer value' (first symbol is not numeric) error message, and none data must be inserted.

If strict mode is disabled then warning is generated instead of error, and the value is converted to numeric (all symbols starting from first non-numeric one are truncated, then the value is converted to number, if it is empty string then zero is assigned).

Data type checking (and convertion if needed) is performed firstly, even before BEFORE INSERT trigger.

DEMO

Sign up to request clarification or add additional context in comments.

2 Comments

I enabled it but problem is still remains.
@AmirmohammadFarhang Reproduce your issue on the online fidle and provide the link. 'll look...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.