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

Integrating Azure Blob Storage with Snowflake on AWS: A Guide to Storage Integration and Staging Data

This article offers a comprehensive, step-by-step guide for integrating Azure Blob Storage with a Snowflake…

6 days ago

Getting Started with SnowSQL: Connecting to Your Snowflake Account

In this quick guide, we’ll walk through the essential steps to connect to Snowflake using…

3 weeks ago

A new step in my career as a Senior Data Architect

I am thrilled to share that I have embarked on a new professional journey as…

5 months ago

Data Modeling and its relevance in the Cloud Era

Since 2005, I've immersed myself in the dynamic world of data and its modeling. It's…

6 months ago

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…

12 months ago

List Comprehension and Walrus operator in Python

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

1 year ago