Categories: Uncategorized

Formatting our Postgres scripts with pgformatter in DBeaver

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.

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.

https://strawberryperl.com/

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:

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!

geohernandez

Share
Published by
geohernandez

Recent Posts

Looking back to Kimball’s approach to Data Warehousing

Over time, it's fascinating to witness how certain concepts, approaches, or visions age. Time, in…

5 months ago

List Comprehension and Walrus operator in Python

When we are working with lists, dictionaries, and sets in Python, we have a special…

9 months ago

Playing with some Pandas functions and Airflow operators

Recently, I was dealing with a task where I had to import raw information into…

11 months ago

Using interpolated format strings in Python

The release of Python 3.6 came with exciting functionalities. I want to speak about the…

1 year ago

Getting the last modified directory with Python

Working with os paths is a prevalent task, especially when working on a console application…

1 year ago

First steps for configuring SQL Server with Docker

Sometimes, our working habits could experiment some interesting changes, maybe forced by real needs or…

2 years ago