PostgreSQL Formatting

It is highly important to retain code readability at the stage of writing it. Taking care of code formatting, syntax check, and code completion, the PostgreSQL Code Formatter feature built-in dbForge Studio for PostgreSQL will let you stay focused on the task.

Configuring Formatting Options

To configure formatting options and customize formatting profiles:

1. On the Tools menu, select Options.

2. In the dialog box, that opens click Formatting.

Formatting Options

3. Two tabs are available under the Formatting option: General, where you can tune your formatting, and Profiles, where you can customize the existing profiles or add the new ones.

4. Make the necessary configuration changes and click OK.

Formatting your code

To format the code of a document, do one of the following:

  • Right-click the SQL query body and then under the Format menu option, select Format Document.
  • On the Edit menu, under the Advanced menu option select Format Document.
  • Press Ctrl+K,D.

To format the current statement, do one of the following:

  • Right-click the SQL query body and then under the Format menu option, select Format Current Statement.
  • On the Edit menu, under the Advanced menu option select Format Current Statement.
  • Press Ctrl+K,S.

To format a certain code fragment, do one of the following:

  • Select and right-click the fragment you want to format. Then under the Format menu option select Format Selection.
  • On the Edit menu, under the Advanced menu option select Format Selection.
  • Press Ctrl+K,F.

Format Selection

Formatting SQL scripts and queries has never been easier.

Customizing your formatting profile

A formatting profile comprises a saved set of options for your SQL document layout. To create or edit a formatting profile, on the Tools menu, click Options. Then in the menu that opens, select Profiles under the Formatting menu option.

dbForge Studio for PostgreSQL has one default profile. To create your own profile, click New Profile, make the necessary configurations, and click OK to save them.

Editing formatting profile

Your active profile is the formatting profile that is highlighted and given in bold. To make a profile active, select it and click Activate.

Activating formatting profile

To edit a profile, select it and click Edit Profile.

Note:

With dbForge SQL formatting tool built-in Studio for PostgreSQL you can switch between formatting profiles within one SQL document.

To apply a different formatting profile for certain segments of code in a query:

1. Select and right-click a code segment you want to format.

2. Under the Active Format Profile menu option switch to a profile you want.

Sharing formatting profiles

dbForge Studio for PostgreSQL allows you to share formatting styles with your colleagues to enforce common layout and coding standards within your team.

Profiles are stored as XML files. To share styles with your team:

1. In the Formatting profiles window, right-click the body of the window, and select Show in Folder.

2. Copy the profile you want to share.

3. Open or create the shared folder you want to use, and paste the profile you want to share into it.

4. Share the name and location of the folder with the team.

Other dbForge Studio for PostgreSQL users can then use the same formatting profile by providing a path to your profile in the New Profile window.

Sharing formatting profile

The PostgreSQL Formatter feature is available in the Standard Edition of dbForge Studio for PostgreSQL.