Skip to content

Commit fbc2b10

Browse files
committed
Fix #28 - Created rule G-1080 Avoid using the same expression on both sides of a relational comparison operator or a logical operator.
1 parent f9bb7a8 commit fbc2b10

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# G-1080: Avoid using the same expression on both sides of a relational comparison operator or a logical operator.
2+
3+
!!! tip "Minor"
4+
Maintainability, Efficiency, Testability
5+
6+
## Reason
7+
8+
Using the same value on either side of a binary operator is almost always a mistake. In the case of logical operators, it is either a copy/paste error and therefore a bug, or it is simply wasted code and should be simplified.
9+
10+
This rule ignores operators `+`, `*` and `||`, and expressions: `1=1`, `1<>1`, `1!=1`, `1~=1` and `1^=1`.
11+
12+
## Example (bad)
13+
14+
``` sql
15+
select emp.first_name
16+
,emp.last_name
17+
,emp.salary
18+
,emp.hire_date
19+
from employees emp
20+
where emp.salary > 3000 or emp.salary > 3000
21+
order by emp.last_name, emp.first_name;
22+
```
23+
24+
## Example (good)
25+
26+
``` sql
27+
select emp.first_name
28+
,emp.last_name
29+
,emp.salary
30+
,emp.hire_date
31+
from employees emp
32+
where emp.salary > 3000
33+
order by emp.last_name, emp.first_name;
34+
```

0 commit comments

Comments
 (0)