pgfmt

command module
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 7, 2026 License: MIT Imports: 4 Imported by: 0

README

pgfmt

A PostgreSQL SQL formatter. Reads SQL from stdin, outputs formatted SQL to stdout.

Uses libpg_query to parse SQL with the actual PostgreSQL parser.

Install

go install github.com/middle-management/pgfmt@latest

Usage

echo "SELECT id,name FROM users WHERE active=true" | pgfmt
pgfmt < query.sql

LSP Server

pgfmt includes an LSP server that provides formatting and diagnostics for SQL files.

Install
go install github.com/middle-management/pgfmt/cmd/pgfmt-lsp@latest
Editor Setup

Neovim (via nvim-lspconfig):

vim.lsp.config['pgfmt'] = {
  cmd = { 'pgfmt-lsp' },
  filetypes = { 'sql' },
  root_markers = { '.git' },
}
vim.lsp.enable('pgfmt')

VS Code (via a generic LSP client like vscode-languageclient):

{
  "pgfmt.server.path": "pgfmt-lsp"
}

Zed — install the pgfmt Zed extension from the extension registry. It bundles pgfmt-lsp and downloads it automatically — no manual setup required.

Then enable formatting in .zed/settings.json or ~/.config/zed/settings.json:

{
  "languages": {
    "SQL": {
      "formatter": "language_server",
      "format_on_save": "on"
    }
  }
}

See the extension README for advanced configuration, including how to use a custom binary path.

Features
  • Formatting — format SQL files using textDocument/formatting
  • Diagnostics — parse errors reported on open and change

Build from source

git clone https://github.com/middle-management/pgfmt.git
cd pgfmt
go build -o pgfmt .
go build -o pgfmt-lsp ./cmd/pgfmt-lsp

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cmd
pgfmt-lsp command
pgfmt-print command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL