I am trying to add external SQL formatting utility to pgAdmin.

There is an option available in pgAdmin3 in Preferences -> Query tool -> Query editor called external formatting utility

I set up python tool sqlparse. It has command line utility called sqlformat. pgAdmin3 requires external formatting utility to accept stdin and sqlformat --help says

Use "-" as FILE to read from stdin.

When I write:

sqlformat -

... as external formatting utility I am getting error

execvp(sqlformat, -) failed with error 2!

When I am trying to wrap it in shell script like that:

sqlformat --reindent --keywords upper --identifiers lower -

... I am getting error

line 2: sqlformat: command not found

Nevertheless my shell script works when I am calling it directly:

cat in.sql | ~/sqlformat.sh > out.sql

How to fix it?

  • Is sqlformat in your $PATH where you run pgAdmin3? You haven't got any relative pathnames in $PATH, I hope? Did you try using an absolute pathname to sqlformat in your script? (i.e. #!/bin/sh , exec /usr/bin/sqlformat ..., or whatever the right location is) – Toby Speight Sep 6 '18 at 14:05
  • BTW error 2 is ENOENT 2 No such file or directory, which is consistent with what you get when you go via Bash. – Toby Speight Sep 6 '18 at 14:08

I still can't figure out how to call sqlformat directly from pgAdmin and why sqlformat is unavailable in shell script when it is called via pgAdmin, but I've come to a solution.

Find full path to utility using:

type -a sqlformat

Replace path to utility in shell script:

/usr/local/bin/sqlformat --reindent --keywords upper --identifiers lower -

And pass this shell script into pgAdmin

|improve this answer|||||
  • If someone can give better answer - you are welcome, because I don't have any explanations yet – Nick Roz Aug 8 '16 at 16:18
  • Did you try using the full pathname in pgAdmin? – Toby Speight Sep 6 '18 at 14:09

You don't need a script, you can simply add to the field 'External formatting utility':

sqlformat --reindent --keywords upper --identifiers lower -

It worked for me.

|improve this answer|||||
  • But the problem is that squlformat wasn't found on the search path! The shell script seems to be merely an attempt to diagnose the problem. – Toby Speight Sep 6 '18 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.