How do I pretty format my SQL query in DBeaver?

Viewed 57792

I use DBeaver for my main IDE to query multiple databases. When I query a table, it automatically generates a long select statement with all columns in one line.

When I am making more complex queries, this gets very cumbersome to work with and read. I would like to view the select values on separate lines rather than one long string.

Is there an easy way (perhaps by using Notepad++ or Sublime Text) to break up the query (with line breaks after the commas)?

For example,

select name, address, city, state, country, zip_code, birthday, membership_type 
from customers

to

select
name,
address,
city,
state,
country,
zip_code,
birthday,
membership_type
from customers
6 Answers

DBeaver has a shortcut for this purpose. In SQL Editor: enter image description here

Yes there is. I use Notepad++ because it is free and I use it for everything! Anyways, Notepad++ has a Plugin called: Poor Man's T-SQL Formatter. It works with a click of a button. You also get a few custom options like if you want to auto capitalize table names, etc.

enter image description here

Select a query to be formatted and Ctrl+shift+F does the work. I am using DBeaver 6.3.0

there is another plugin for formatting SQL in Notepad++. It can be found here: SQLinForm SQL Formatter and has 100+ formatting options with code folding and color formatting. There is also a free plugin available.

SQLinForm SQL Formatter

In SublimeText I assume you have already installed Package Control? If not do so as soon as you can, it is a vital tool.

From Package Control there are a number of options to do what you want to do. Here are some options

I would start with SqlBeautifier and then try others to find which one suits your taste best.

use backtick ` instead of quote " or '

Related