PG_FORMAT(1) User Contributed Perl Documentation PG_FORMAT(1) (NAME) pg_format - SQL PostgreSQL (DESCRIPTION) SQL SQL-92 SQL-99 SQL-2003 SQL-2008 SQL-2011 PostgreSQL . . pgFormatter CGI . HTML . CGI 'Accept: application/json' JSON . CGI . / (Terminal/console execution) : pg_format [] file.sql PostgreSQL SQL queries and PL/PGSQL code beautifier. : file.sql - stdin . SQL stdout -o | --output . : -a | --anonymize : (literals) . -b | --comma-start : ( -e ). -B | --comma-break : insert . -c | --config FILE : . ./.pg_format $HOME/.pg_format XDG $XDG_CONFIG_HOME/pg_format/pg_format.conf . -C | --wrap-comment : --wrap-limit . -d | --debug : . . -e | --comma-end : (). -f | --function-case N: PostgreSQL. : 0. : 0=> 1=> 2=> 3=> . -F | --format STR : : text html. : text. -g | --nogrouping : . . -h | --help : . -i | --inplace : . -k | --keep-newline : plpgsql. -L | --no-extra-line : . -m | --maxlength SIZE : . : (no truncate). -M | --multiline : -p --placeholder. -n | --nocomment : SQL. -N | --numbering : . -o | --output file : . : stdout. -p | --placeholder RE : (regex) . -r | --redshift : RedShift SQL. --extra-keyword 'redshift' . -s | --spaces size : . -S | --separator STR : ('). -t | --format-type : . -T | --tabs : -s . -u | --keyword-case N : . : 2. : 0=> 1=> 2=> 3=> . -U | --type-case N : . : 1. : 0=> 1=> 2=> 3=> . -v | --version : pg_format . -w | --wrap-limit N : . -W | --wrap-after N : . : . -X | --no-rcfile : rc ( ./.pg_format $HOME/.pg_format $XDG_CONFIG_HOME/pg_format). --config / -c . --extra-function FILE : PostgreSQL. --extra-keyword FILE : PostgreSQL. 'redshift' Redshift pgFormatter . --no-space-function : . --redundant-parenthesis: DML. : cat samples/ex1.sql | pg_format - pg_format -n samples/ex1.sql pg_format -f 2 -n -o result.sql samples/ex1.sql CGI (CGI context) pg_format cgi-bin CGI ( .cgi ) . logo_pgformatter.png icon_pgformatter.ico CGI pg_format.cgi . SQL : http://sqlformat.darold.net pg_format CGI html . . CGI JSON . : yum install perl-cgi yum install perl-json apt install libcgi-pm-perl apt install libjson-perl . (INSTALLATION) autodie : sudo yum -y install perl-autodie tarball : version=5.3 # wget https://github.com/darold/pgFormatter/archive/refs/tags/v${version}.tar.gz tar xzf v${version}.tar.gz cd pgFormatter-${version}/ perl Makefile.PL make && sudo make install cd ../ && rm -rf v${version}.tar.gz && rm -rf pgFormatter-${version} # pg_format /usr/local/bin/pg_format /usr/local/share/man/man1/pg_format.1 . 'site' . /usr/ INSTALLDIRS='perl' Makefile.PL . /usr/bin/pg_format /usr/share/man/man1/pg_format.1 . : perl Makefile.PL INSTALLDIRS=vendor INSTALLDIRS site . : make test pgFormatter : docker build -t darold.net/pgformatter . : cat file.sql | docker run --rm -a stdin -a stdout -i darold.net/pgformatter - (SPECIAL FORMATTING) -W --wrap-after (Option -W, --wrap-after) . pgFormatter . SELECT FROM . : SELECT a, b, c, d FROM t_1, t_2, t3 WHERE a = 10 AND b = 10; -W 4 : SELECT a, b, c, d FROM t_1, t_2, t3 WHERE a = 10 AND b = 10; . -w --wrap-limit (Option -w, --wrap-limit) . . . . -C --wrap-comment (Option -C, --wrap-comment) -w --wrap-limit . . -t --format-type (Option -t, --format-type) : * / * DDL PUBLICATION POLICY * GROUP BY . -g --nogrouping (Option -g, --nogrouping) pgFormatter : BEGIN; INSERT INTO foo VALUES (1, 'text 1'); INSERT INTO foo VALUES (2, 'text 2'); ... COMMIT; pgFormatter : BEGIN; INSERT INTO foo VALUES (1, 'text 1'); INSERT INTO foo VALUES (2, 'text 2'); ... COMMIT; DML . -L --no-extra-line (Option -L, --no-extra-line) pgFormatter ; plpgsql . . --extra-function (Option --extra-function) pgFormatter PostgreSQL . ( ) --extra-function pgFormatter PostgreSQL . --extra-keyword (Option --extra-keyword) pgFormatter PostgreSQL . ( ) --extra-keyword pgFormatter PostgreSQL . 'redshift' pgFormatter . -r | --redshift . --no-space-function (Option --no-space-function) . pgFormatter : DROP FUNCTION IF EXISTS app_public.hello (a text); : DROP FUNCTION IF EXISTS app_public.hello(a text); --redundant-parenthesis (Option --redundant-parenthesis) pgFormatter DML . . --vertical-align (Option --vertical-align) CREATE TABLE . DEFAULT . : CREATE TABLE example ( id serial PRIMARY KEY, -- some comment name varchar(100) NOT NULL, -- another comment email varchar(100) NOT NULL, -- third comment created_at timestamp with time zone DEFAULT CURRENT_TIMESTAMP -- last comment ); . . (HINTS) (Configuration) pg_format pg_format . pgFormatter ./.pg_format $HOME/.pg_format $XDG_CONFIG_HOME/pg_format/pg_format.conf -c | --config . CGI pg_format.cgi pg_format.conf CGI . doc/pg_format.conf.sample . $XDG_CONFIG_HOME/pg_format $HOME/.pg_format pg_format -X | --no-rcfile . (Formatting from stdin) pg_format - SQL stdin . SQL `ctrl+d` . $ pg_format select * from customers; < ctrl+d > : echo "select * from customers;" | pg_format VI (Formatting from VI) pgFormatter ~/.vimrc : au FileType sql setl formatprg=/usr/local/bin/pg_format\ - gq pgFormatter . : ESC+gq+G . ESC+gq+2j . David Fetter . (Neo)vim pg_format SQL . Anders Riutta (Neo)vim. Atom (Formatting from Atom) atom pg-formatter Node.js pgFormatter . : * . * SQL . : pg-formatter Atom : apm install pg-formatter : Ctrl-Alt-F ( ) : 'ctrl-alt-p': 'pg-formatter:format' SQL ( ). : https://atom.io/packages/pg-formatter https://github.com/gajus/pg-formatter . Alex Fedoseev atom. Visual Studio (Formatting from Visual Studio) Brady Holt Visual Studio Code SQL PostgreSQL pgFormatter . https://marketplace.visualstudio.com/items?itemName=bradymholt.pgformatter . (Prevent replacing code snippets) -p --placeholder SQL pgFormatter . : SELECT * FROM projects WHERE projectnumber IN <> AND username = <>; pgFormatter << >> (bit-shift) . pgFormatter . : pg_format samples/ex9.sql -p '<<(?:.*)?>>' . (-w 60) (-C) (URL) . . : pg_format samples/ex62.sql -C -w 60 -p 'https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' . (Prevent dynamic code formatting) pgFormatter . pgFormatter . EXECUTE . -S --separator . Node.js (Node.js thin-wrapper) Gajus Kuizinas Node.js pgFormatter . https://github.com/gajus/pg-formatter . CSS CGI (Customize CSS for the CGI output) HTML CSS custom_css_file.css CGI pgFormatter . CSS . CSS HTML . pgFormatter API (Using pgFormatter as an API) HTTP 'Accept' 'application/json' CGI pgFormatter API . "$self->{ 'enable_api' } = 0" "set_config" lib/pgFormatter/CGI.pm . PRE-COMMIT HOOK (USING AS PRE-COMMIT HOOK) - repo: https://github.com/darold/pgFormatter rev: "v5.8" hooks: - id: pg_format args: ["--inplace", "--wrap-limit", "120"] files: '.*\.sql$' (AUTHORS) pgFormatter Gilles Darold Hubert depesz Lubaczewski . (COPYRIGHT) 2012-2026 Gilles Darold. . (LICENSE) pgFormatter PostgreSQL (PostgreSQL Licence) . SQL::Beautify pgFormatter (C) 2009 Jonas Kramer Artistic License 2.0 . perl v5.42.2 2026-09-04 PG_FORMAT(1)