Skip to content

Commit 74726da

Browse files
add G-3182, closes #197
1 parent be04a26 commit 74726da

File tree

1 file changed

+36
-0
lines changed
  • docs/4-language-usage/3-dml-and-sql/1-general

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# G-3182: Always specify column names instead of positional references in GROUP BY clauses.
2+
3+
!!! bug "Blocker"
4+
Reliability
5+
6+
## Restriction
7+
8+
Oracle Database 23c
9+
10+
## Reason
11+
12+
If you use a numeric literal in the `group by` clause in an Oracle Database prior to version 23c, then this literal is not required. It is simply a constant.
13+
14+
Starting with Oracle Database 23c, it is possible to use a literal in the `group by` clause to refer to a column name in the `select` list. However, this only works if the `group_by_position_enabled` parameter is set to `true`. In any case, it is not convenient for the readers of the code to have to count the columns in the `select` list to know how the result is grouped.
15+
16+
Since the meaning of a `literal` depends on the configuration and database version, the intention is unclear and might lead to an incorrect result.
17+
18+
## Example (bad)
19+
20+
``` sql
21+
select job_id
22+
,sum(salary) as sum_salary
23+
from employees
24+
group by job_id,2 -- violates also G-1050
25+
order by job_id;
26+
```
27+
28+
## Example (good)
29+
30+
``` sql
31+
select job_id
32+
,sum(salary) as sum_salary
33+
from employees
34+
group by job_id
35+
order by job_id;
36+
```

0 commit comments

Comments
 (0)