You know I had to do it as soon as I found it was possible. Yes, I installed and enabled AI in the DBeaver Query Editor so I can use AI with my PostgreSQL database work. Let’s face it. It was inevitable. However, the setup isn’t intuitive.
Setting Up in DBeaver
I’m going to assume you’re on the Community Edition of DBeaver. First, got to the “Help” menu and then “New Software”. A window will open up. Right at the top is a drop down labeled “Work with.” Select that and then select “DBeaver – AI support – https://dbeaver.io/update/ai/latest/.” Next, select “DBeaver AI Support” down in the window and it should look like this:

At the bottom of the screen you can pick finish, or hit next and review stuff. Either way, the install is pretty quick. Now we have to configure it. Go to the “Windows” menu and “Preferences.” That opens another window. Expand the “General” tab on the left and select “AI”. You’ll see something like this, but not filled in as mine is:

You will need an account with OpenAI and you’ll need an API key from there. I put mine through Github Copilot because I manage quite a few things through there for demo purposes. Paste in the key and click on the Authorize button (not shown). That’ll connect you to GitHub and provide authorization. From there, it’s just a question of putting this to work.
Using AI in DBeaver
My first example is a silly one, I freely admit. I’m using the BlueBox database by Ryan Booz for most of my PostgreSQL testing and demos. So, I connected up to the cluster and that database and provided the following prompt (you have to tell it that it’s going to do AI work using @ai):
@ai CREATE a query that retrieves data from film AND film_genre TABLES IN the bluebox SCHEMA
It can do code completion, and you can be sure I’ll be testing that out. However, I just wanted to see it in action, immediately. Executing this like it was a query, I was first asked if it could access my database. Huzzah! A little security. I said yes. I actually got data back, like it was a query. And over in the output window I saw this:

Ok, yeah, I hate the quotes too. I’ll see if it’s possible to remove them with a better prompt, but hey, right there, it works. Not only did it work, note that it figured out that the the film table has an array of genre_ids and it would have to use that as the criteria for the ON clause. Oooh!
Conclusion
It’s not exactly earth shattering wonder here. As I keep saying about AI, it’s another tool in the toolbox. Now, in my favorite PostgreSQL toolbox, DBeaver, I’ve got one of my favorite tools, an AI engine. I can’t wait to what it does with code completion. Maybe I’ll put up another blog post on that (off to do some UDT work for a different article, so plenty of opportunities).