Skip to content

Commit a27e09e

Browse files
committed
Fix #34 - Created rule G-2145 and G-3115 about self-assignment of variables and columns.
1 parent fbc2b10 commit a27e09e

File tree

2 files changed

+58
-0
lines changed
  • docs/4-language-usage

2 files changed

+58
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# G-2145: Never self-assign a variable.
2+
3+
!!! tip "Minor"
4+
Maintainability
5+
6+
## Reason
7+
8+
There is no reason to assign a variable to itself. It is either a redundant statement that should be removed, or it is a mistake where some other value was intended in the assignment.
9+
10+
## Example (bad)
11+
12+
``` sql
13+
declare
14+
l_function_result pls_integer;
15+
l_parallel_degree pls_integer;
16+
begin
17+
l_function_result := maintenance.get_config('parallel_degree');
18+
l_parallel_degree := l_parallel_degree;
19+
end;
20+
/
21+
```
22+
23+
## Example (good)
24+
25+
``` sql
26+
declare
27+
l_function_result pls_integer;
28+
l_parallel_degree pls_integer;
29+
begin
30+
l_function_result := maintenance.get_config('parallel_degree');
31+
l_parallel_degree := l_function_result;
32+
end;
33+
/
34+
```
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# G-3115: Avoid self-assigning a column.
2+
3+
!!! tip "Minor"
4+
Maintainability
5+
6+
## Reason
7+
8+
There is normally no reason to assign a column to itself. It is either a redundant statement that should be removed, or it is a mistake where some other value was intended in the assignment.
9+
10+
One exception to this rule can be when you attempt to fire cross edition triggers when using Edition Based Redefinition.
11+
12+
## Example (bad)
13+
14+
``` sql
15+
update employees
16+
set first_name = first_name;
17+
```
18+
19+
## Example (good)
20+
21+
``` sql
22+
update employees
23+
set first_name = initcap(first_name);
24+
```

0 commit comments

Comments
 (0)