dbeaver / dbeaver/dbeaver

Possible bug using query parameters

Open
#3,458 4 comments 0 reactions 0 assignees View on GitHub
xf:sql xf:sql editor
Dominant language
Java
Stars
51.8k
Forks
4.4k
Avg merge
3d 9h
Merged PRs (30d)
189

Description

Hello,

I've found an odd behavior in DBeaver when using query parameters.

- I've a function that inserts a record in a table and returns the id of the inserted record;
- I want to assign the value of the inserted id to a parameter;
- I want to use the parameter in 2 other querys;

For simplicity's sake let's assume that the function is called **insert_record** and takes no parameters. Let's also assume the table in which I'm going to insert records is called **test_table**.

```
@set record_id = insert_record()
select :record_id;
select :record_id + 1;
```

If I execute this script, two thing happen that are quite strange to me:
1. even if i set a default value for :record_id, the popup asking me for a value has a blank value column;
2. every time I use the parameter :record_id in a script the popup asks me for a new value. And since the value is a function, **insert_record** gets executed every time I use :record_id in a script

In my opinion this is a bug. The correct behavior would be to ask only one time for the value and then use it anytime it appears in the script, executing the function only one time.
Also, if I set a default value for a parameter I'm expecting to see it as a proposed value in the parameters popup.

Best regards,
Cristiano

Contributor guide

Open the contributing guide

Research direction

Reproduce the behavior in DBeaver's SQL editor using the supplied @set and two SELECT statements, including a default parameter value. Trace how the parameter popup and script execution handle repeated :record_id references. Done means the default appears in the popup and the function-backed parameter is requested and evaluated once, then reused.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, sql
Domain
database, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.