SQL Syntax Troubleshooting?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: SQL 语法求解惑?

| username: h5n1

Why can a library compatible with MySQL execute SQL even when the WHERE condition is not fully written?

TiDB:

MySQL:

Ali-DRDS:
c6ea586b36d52048403c7f1ec7b38bc

Oracle:

OB-MySQL:
405a7073d859f8e0be2014002e9536c

OB-Oracle:
3e029aebed6e1dc0eabc1302226c201

| username: ShawnYan | Original post link

In MySQL, the expression following WHERE is not that strict. “WHERE acct_id” is equivalent to “WHERE 1”.

| username: h5n1 | Original post link

I feel this way is prone to problems.

| username: ShawnYan | Original post link

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 :sweat:

| username: h5n1 | Original post link

Yes, if the condition and field are split into two lines, and the condition is commented out, it will be executed directly.

| username: 小龙虾爱大龙虾 | Original post link

It should be filtered by int. I tested with varchar(10).

| username: Kongdom | Original post link

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.

| username: wuxiangdong | Original post link

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.

| username: alfred | Original post link

You can set sql_mode to avoid it, right?

| username: forever | Original post link

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.

| username: h5n1 | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.