DBeaver, How to declare variables and use them?

Elliott Urrutia picture Elliott Urrutia · Jun 12, 2019 · Viewed 18.8k times · Source

i just want to know if it is possible to declare variables on the DBeaver´s sql editor and use them on a query

Answer

nicoschl picture nicoschl · Oct 9, 2019

You have to enable variable processing in the "SQL Processing" settings of DBeaver -> Window -> Preferences -> Database -> Editors -> SQL Editor -> SQL Processing. There is a block on Parameters with settings you can change. See the Dynamic Parameter binding section on the wiki.

enter image description here

You should then be able to do:

@set date = '2019-10-09'

SELECT ${date}::DATE, ${date}::TIMESTAMP WITHOUT TIME ZONE

which produces:

| date       | timestamp           |
|------------|---------------------|
| 2019-10-09 | 2019-10-09 00:00:00 |