{"id":43710,"library":"psqlformat","title":"psqlformat","description":"PostgreSQL SQL syntax beautifier wrapping the Perl-based pgFormatter. v1.33.0 (released 2023-01-15) provides a CLI and JavaScript API for formatting SQL files, with options for indentation, keyword casing, comma placement, and comment removal. Key differentiators: specifically targets PostgreSQL dialect, supports extensive formatting rules (keywordCase, functionCase, typeCase), and offers both library and CLI usage. Requires Perl runtime. Actively maintained with monthly releases.","status":"active","version":"1.33.0","language":"javascript","source_language":"en","source_url":"https://github.com/bradymholt/psqlformat","tags":["javascript","sql","postgres","postgreSQL","formatting","typescript"],"install":[{"cmd":"npm install psqlformat","lang":"bash","label":"npm"},{"cmd":"yarn add psqlformat","lang":"bash","label":"yarn"},{"cmd":"pnpm add psqlformat","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"The underlying pgFormatter tool is written in Perl and must be installed on the system.","package":"perl","optional":true}],"imports":[{"note":"Package ships ES module by default (since v1.0.0). CJS require() will work if using bundler that handles ESM, but direct require may fail.","wrong":"const psqlformat = require('psqlformat')","symbol":"default","correct":"import psqlformat from 'psqlformat'"},{"note":"Named export for formatting a single SQL string. Only available in ESM environment.","wrong":"const { format } = require('psqlformat')","symbol":"format","correct":"import { format } from 'psqlformat'"},{"note":"Reads a file and formats its SQL content. Returns a Promise<string>.","wrong":"","symbol":"formatFromFile","correct":"import { formatFromFile } from 'psqlformat'"}],"quickstart":{"code":"import { format } from 'psqlformat';\n\nconst sql = process.env.SQL ?? 'SELECT id, name FROM users WHERE id = 1';\nconst formatted = await format(sql, { spaces: 2, keywordCase: 'lowercase' });\nconsole.log(formatted);\n// Output:\n// select id,\n//   name\n// from users\n// where id = 1","lang":"typescript","description":"Demonstrates formatting a SQL string with custom options (2 spaces, lowercase keywords) using the ESM module."},"warnings":[{"fix":"Install Perl via your package manager (e.g., 'sudo apt-get install perl' on Ubuntu, or 'brew install perl' on macOS).","message":"Requires Perl to be installed and available on PATH. Without Perl, formatting operations will fail with a spawn error.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use dynamic import: const psqlformat = await import('psqlformat'); or import statement in an ESM context.","message":"In version 1.0.0, the package switched from CommonJS to ESM-only. Calling require('psqlformat') will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Use '--commaEnd=false' instead.","message":"The CLI option '--commaStart' is deprecated in favor of '--commaEnd' with false. It will be removed in a future version.","severity":"deprecated","affected_versions":">=1.15.0"},{"fix":"For large files, use formatFromFile which reads the file in chunks.","message":"Formatting large files may block the event loop because the underlying Perl process is synchronous. Consider using formatFromFile with streaming for large files.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'-01':15 '-15':16 '2023':14 'activ':61 'api':22 'base':10 'beautifi':5 'case':32 'cli':19,56 'comma':33 'comment':36 'dialect':43 'differenti':39 'extens':45 'file':26 'format':24,46,70 'functioncas':49 'indent':30 'javascript':21,66 'key':38 'keyword':31 'keywordcas':48 'librari':54 'maintain':62 'month':64 'offer':52 'option':28 'perl':9,59 'perl-bas':8 'pgformatt':11 'placement':34 'postgr':68 'postgresql':2,42,69 'provid':17 'psqlformat':1 'releas':13,65 'remov':37 'requir':58 'rule':47 'runtim':60 'specif':40 'sql':3,25,67 'support':44 'syntax':4 'target':41 'typecas':50 'typescript':71 'usag':57 'v1.33.0':12 'wrap':6","created_at":"2026-06-05T17:01:06.357720+00:00","updated_at":"2026-06-05T17:01:06.357720+00:00","problems":[{"fix":"Install Perl (e.g., sudo apt-get install perl) and ensure it's accessible.","cause":"Perl is not installed or not on PATH.","error":"Error: spawn perl ENOENT"},{"fix":"Use import instead of require, or convert your project to ESM.","cause":"Using require() on an ES module.","error":"ERR_REQUIRE_ESM","affected_versions":">=1.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bradymholt/psqlformat#readme","github":"https://github.com/bradymholt/psqlformat","docs":null,"changelog":null,"pypi":null,"npm":"psqlformat","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}