Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: SQL 语法求解惑?
Why can a library compatible with MySQL execute SQL even when the WHERE condition is not fully written?
TiDB:
MySQL:
Ali-DRDS:
Oracle:
OB-MySQL:
OB-Oracle:
In MySQL, the expression following WHERE is not that strict. “WHERE acct_id” is equivalent to “WHERE 1”.
I feel this way is prone to problems.
As long as the field exists, there is no syntax problem, which is equivalent to the expression following where being true.
There is a risk, so it relies on review, otherwise putting it in delete would delete the entire table
Yes, if the condition and field are split into two lines, and the condition is commented out, it will be executed directly.
It should be filtered by int. I tested with varchar(10).
No, you also need to check the value of acct_id. When it is non-zero and non-null, it is equivalent to where 1.
MySQL’s syntax is not very strict, but it can be surprisingly effective. By clearing all sql_mode settings, validation is done entirely during the development and testing phases.
You can set sql_mode to avoid it, right?
where 1 refers to the entire table data. You also need to consider the data type. For character types, it should be converted to numeric types for judgment. For numeric types, use !=0 and is not null. For date types, use is not null.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.