Replies: 1 comment 2 replies
-
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Per discussion with AI...
You're right! DBeaver should have a built-in
${}
variable for the currently selected database, but unfortunately, it doesn’t provide a direct${database}
placeholder in SQL templates.However, you can automate this manually by using:
Workarounds to Dynamically Insert the Current Database Name
1️⃣ Use
SELECT current_database();
in PostgreSQLcurrent_database()
, which you can use in your query templates.${current_db}
variable at execution time.2️⃣ Custom SQL Template to Auto-Insert Database Name
While DBeaver doesn't provide a
${database}
variable, you can create a custom template to insert the current database dynamically.📌 Steps to Create a Custom SQL Template
Go to
Preferences > Editors > SQL Editor > Templates
.Click "New" and enter:
ShowDB
Show current database
Click OK to save.
Usage:
ShowDB
and pressCtrl + Space
, and it will insert:3️⃣ Use a Dynamic SQL Header for Every Query
If you want every query you run to automatically label the database, use:
This will prepend your output with the database name.
Feature Request to DBeaver
DBeaver should have a
${database}
variable similar to${date}
,${time}
, etc.You might want to submit a feature request on [DBeaver GitHub](https://github.com/dbeaver/dbeaver/issues).
Final Takeaway
${database}
variable, but custom templates can help.SELECT current_database();
in PostgreSQL.ShowDB
) can insert the database name for you.Let me know if you need more fine-tuned automation! 🚀
Beta Was this translation helpful? Give feedback.
All reactions