Are you a PostgreSQL enthusiast using DBeaver on a Windows Platform? If you find yourself knee-deep in SQL queries and long for a cleaner, more organized code, then configuring pgFormatter might be the solution you’re looking for. In this post, we’ll dive into the intricacies of setting up pgFormatter within DBeaver on Windows, offering you a streamlined and visually appealing SQL coding experience.
Whether you are a database administrator, developer, or a curious SQL fan, understanding how to integrate pgFormatter into your /DBeaver workflow can significantly enhance your coding efficiency. Let’s embark on this step-by-step journey to configure pgFormatter, making your SQL code more readable and consistent. Let us get started!
What is pgFormatter?
It is an open-source tool used to format SQL and PLPGSQL code, it is widely embraced by the PostgreSQL community. You can find comprehensive details about it on the official PostgreSQL site.
Note: In case you are using Mac or Linux, you can find many resources explaining how to configure SQL Formatter in DBeaver. A useful link is here.
Contents
Installation Prerequisites
Before diving into the use of SQL Formatter tool, you need to ensure the following components are in place:
- Perl
- pgformatter
- DBeaver
First of all, it is mandatory before using SQL Formatter to configure Perl, which is the language used internally by SQL Formatter. Later, we should download SQL Formatter, copy it to a specific directory and finally do the proper configuration on DBeaver. The following sections will explain to you in detail how to do it.
Installing Perl in Windows
For Windows users, the critical first step is to install Perl, the language used internally by SQLFormatter. I recommend using Strawberry Perl, a simple and reliable package available at this link.
My recommendation is to install the System installer version, mainly because the .msi file automatically registers in the PATH. After installation, open the command line and verify the Perl version by running ‘perl -v
‘
Configuring pgFormatter
The pgFormatter package is available in the next links:
- https://github.com/darold/pgformatter
Once you have downloaded the zip file, you should extract it into a target folder, as in this example:
Setting up pgFormatter in DBeaver
At this point, we can go DBeaver and configure the use of pgFormatter as an external formatted. Go to the Windows –> Preferences –> Editors –> Formatting. Once in there, you should follow the instructions on this code:
1 |
perl.exe "Path_of_pg_format_package\pg_format" ${file} |
It is mandatory to mark Use temp file for managing the format on the current code (highlighted). See this example:
pgFormatter in action
At this point, we are ready to start with pgFormatter inside DBeaver. The following image shows you a code without format:
You should select the code and apply the key shortcut combination: Ctrl + Shift + F. Here is the output:
Conclusion
In conclusion, this post provides a straightforward approach to enhancing the appearance of your SQL code using pgFormatter in DBeaver. The ability to customize preferences and further adapt with pgFormatter is a topic we’ll explore in future posts. Happy Coding!