A lightweight VS Code extension that integrates the powerful pg_format CLI for SQL formatting. No npm package dependencies, no abstraction, no magic. It simply runs pg_format with the arguments you configure. Automatically respects your IDE's tab and space size settings.
Overview
pgFormatter2 bridges VS Code and the pg_format CLI, enabling direct SQL formatting within the editor. The extension executes the pg_format command with your configured settings and applies the formatted result to your SQL selections.
Requirements
The pg_format command must be installed on your system. See pgFormatter documentation for installation instructions.
Installation
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "pgFormatter"
- Click Install
Configuration
Configure pgFormatter behavior in VS Code settings under the pgFormatter section.
Core Settings
pgFormatter.pg_format_path - Path to the pg_format executable (default: pg_format)
Full documentation: pgFormatter documentation.
Boolean options can be enabled/disabled individually. Set to null to omit from formatting.
pgFormatter.--anonymize - Obscure all literals in queries
pgFormatter.--debug - Enable debug mode
pgFormatter.--wrap-comment - Apply wrapping to comments
pgFormatter.--nogrouping - Do not group statements
pgFormatter.--keep-newline - Preserve empty lines in PL/pgSQL
pgFormatter.--no-extra-line - Do not add extra empty line at end
pgFormatter.--multiline - Enable multi-line search
pgFormatter.--nocomment - Remove comments
pgFormatter.--numbering - Add statement numbering
pgFormatter.--redshift - Enable Redshift keywords
pgFormatter.--format-type - Try alternative formatting type
pgFormatter.--no-rcfile - Do not read rc files automatically
pgFormatter.--no-space-function - Remove space before function parenthesis
pgFormatter.--redundant-parenthesis - Do not remove redundant parentheses
pgFormatter.--comma-start - Start list with comma
pgFormatter.--comma-end - End list with comma
pgFormatter.--comma-break - Break after each comma
Other Options
pgFormatter.--config - Path to configuration file
pgFormatter.--placeholder - Regex for protected code
pgFormatter.--separator - Dynamic code separator
pgFormatter.--extra-function - File containing extra functions
pgFormatter.--extra-keyword - File containing extra keywords
pgFormatter.--maxlength - Maximum query length
pgFormatter.--wrap-limit - Wrap queries at column width
pgFormatter.--wrap-after - Wrap lists after N columns
pgFormatter.--format - Output format: text or html (default: not set)
pgFormatter.--function-case - Function case: 0 (unchanged), 1 (lowercase), 2 (uppercase), 3 (capitalize)
pgFormatter.--keyword-case - Keyword case: 0 (unchanged), 1 (lowercase), 2 (uppercase), 3 (capitalize)
pgFormatter.--type-case - Type case: 0 (unchanged), 1 (lowercase), 2 (uppercase), 3 (capitalize)
Example Configuration
Add to your VS Code settings.json:
{
"pgFormatter.--wrap-after": 2,
}
License
GNU Affero General Public License v3.0
Author
Ninh Pham (ReeganExE)