dbeaver / dbeaver/dbeaver

Boundaries of a query with recursive common table expression are detected incorrectly if a query contains an empty line

Open
#35,133 3 comments 0 reactions 1 assignee Claimed by @E1izabeth View on GitHub
xf:sql execution
Dominant language
Java
Stars
51.8k
Forks
4.4k
Avg merge
3d 8h
Merged PRs (30d)
188

Description

### Description

- use this code (notice the empty line before the last word "select"):

```
with recursive all_data as (
select *
from (values(1, 1, 10),(1, 2, 3),(1, 3, 7),(1, 4, 1),(1, 5, 2),(2, 1, 6),(2, 2, 4),(2, 3, 5),(2, 4, 8),(2, 5, 1)) as s(gr, id, quantity)
),
ct AS (
select *, c.quantity AS sm
from all_data AS c
WHERE id = 1
UNION ALL
select c2.*, c.sm + c2.quantity AS sm
from ct AS c
JOIN all_data AS c2 ON c2.id = c.id + 1 AND c.gr = c2.gr
)

SELECT *
FROM ct
ORDER BY gr, id

```

- set caret to the 8th line
- press Ctrl + Enter (results - on the screen 1)
- set caret to the 16th line
- press Ctrl + Enter (results - on the screen 2)
- remove the empty line and repeat the same steps (there will be no error)

Screen 1:

![изображение](https://github.com/user-attachments/assets/0ead1502-91b1-4fad-be5b-7254e7e8daf4)

Screen 2:

![изображение](https://github.com/user-attachments/assets/b63e2398-1088-4dd4-9d7b-5dfb2fc0df2f)

### DBeaver Version

Community Edition 24.1.5.202408012322

### Operating System

Windows 10

### Database and driver

PostgreSQL 16
PostgreSQL JDBC Driver 42.7.2

### Steps to reproduce

_No response_

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.