32

I would like to autoformat / beautify my SQL-queries directly in pgAdmin4. I know this feature from Java-developing in Eclipse, where I can beautify the whole code using a simple shortcut.

I only found a command line solution so far that makes my SQL queries pretty: pgFormatter.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
coding_bird
  • 483
  • 1
  • 4
  • 5

5 Answers5

56

Try the following command:

shift+Ctrl+k
Elletlar
  • 3,136
  • 7
  • 32
  • 38
Amazigh
  • 595
  • 1
  • 4
  • 2
  • 2
    I'm not sure what the context of this answer is so many years later, but this doesn't appear to have any effect in pgAdmin 4. – k3davis Dec 09 '20 at 13:23
  • Actually thats incorrect, it does in-fact format for me using pgadmin 4.4, in chrome on windows 10 – Ronnyek Feb 11 '21 at 02:30
  • 4
    works but formats it really badly. Its more readable when this command is not used – Tobi Feb 12 '21 at 15:03
  • also this breaks jsonb constructions – grigson Sep 13 '21 at 05:49
  • It seems there's no way to revert to the default formatting configuration, so be cautions if you start tweaking it - you might get weird(er) results and not be able to easily revert those changed. – devklick Jul 12 '23 at 11:20
11

Currently this feature is not implemented in pgadmin4 which does autoformat or beautify SQL-queries automatically but you can expect this feature in near future version as developers are working on this feature.

Developers discussion mail thread for the feature: https://www.postgresql.org/message-id/CAPG3WN46pgzxKERPpr4TSpVFtyeMhParjvKAUzXWOuwZ4qJPhg@mail.gmail.com

Murtuza Z
  • 5,639
  • 1
  • 28
  • 52
10

In pgAdmin5 on macOS this can be done using Shift + Cmd + K.

Here is where you can find it in the UI: Screenshot

SamB
  • 2,621
  • 4
  • 34
  • 39
4

Still not implemented afaict, but an option would be to use some online tool.

I've successfully used: https://sqlformat.org/

estani
  • 24,254
  • 2
  • 93
  • 76
1

Try Shift Shift + ctrl + k

You can use command + Shift + k for SQL code format or beautify.

Umair Asghar
  • 181
  • 4
  • 14