Is it possible to autoformat / beautify SQL queries using pgAdmin4?
Asked Answered
P

8

36

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.

Protocol answered 3/6, 2017 at 15:0 Comment(0)
A
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

Anglonorman answered 3/6, 2017 at 16:45 Comment(1)
The answer is outdated.Endostosis
C
65

Try the following command:

shift+Ctrl+k
Conklin answered 12/11, 2020 at 6:38 Comment(5)
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.Skutchan
Actually thats incorrect, it does in-fact format for me using pgadmin 4.4, in chrome on windows 10Priggish
works but formats it really badly. Its more readable when this command is not usedBergess
also this breaks jsonb constructionsTremolo
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.Trattoria
F
16

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

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

Furnace answered 11/5, 2021 at 6:14 Comment(0)
A
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

Anglonorman answered 3/6, 2017 at 16:45 Comment(1)
The answer is outdated.Endostosis
F
4

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

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

Frawley answered 17/7, 2019 at 11:42 Comment(0)
O
1

Try Shift Shift + ctrl + k

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

Observer answered 26/6, 2021 at 12:58 Comment(0)
I
1

I am using pgAdmin 4 v8.8 on MacOS and cmd+k works for me!

Impatiens answered 19/7, 2024 at 14:6 Comment(1)
CMD+K? Not SHIFT+CMD+K as other answers indicate?Sik
S
0

On windows you can now use ctrl + k to format SQL. If your are on a different OS, I found the keyboard shortcut under the Query Tool | look for the pencil toolbar button and click it | look for Format SQL. I'm using pgAdmin 4 version 8.9.

Splashboard answered 9/7, 2024 at 15:26 Comment(0)
M
0

To format SQL in pgAdmin4 :

  • Cmd + k in Mac
  • Shift + ctrl + k in other OS

Also pgAdmin SQL formater offers different formatting preferences as shown below. This option in available in Preferences > SQL Formatting enter image description here

Marikomaril answered 26/7, 2024 at 10:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.