{"id":43696,"library":"prettier-sql","title":"Prettier SQL","description":"Prettier SQL v5.1.1 is a JavaScript library for pretty-printing SQL queries. It supports 12 dialects including MySQL, PostgreSQL, BigQuery, and Spark. It started as a port of a PHP library but has diverged considerably. Released regularly via npm, it offers both programmatic and CLI usage. Key differentiators: extensive dialect support, uppercase/lowercase control, placeholder replacement, and zero runtime dependencies. Types are included.","status":"active","version":"5.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/inferrinizzard/prettier-sql","tags":["javascript","sql","formatter","format","n1ql","redshift","spark","whitespace","mysql","typescript"],"install":[{"cmd":"npm install prettier-sql","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-sql","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-sql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v5; CommonJS require() still works but named imports are preferred.","wrong":"const format = require('prettier-sql').format","symbol":"format","correct":"import { format } from 'prettier-sql'"},{"note":"Default export is an object with format method; avoid using default in ESM if you only need format.","wrong":"const prettierSql = require('prettier-sql')","symbol":"default","correct":"import prettierSql from 'prettier-sql'"},{"note":"No separate formatDialect export; pass dialect via config.language.","wrong":"import { formatDialect } from 'prettier-sql'","symbol":"formatDialect","correct":"import { format } from 'prettier-sql' // use language option in config"}],"quickstart":{"code":"import { format } from 'prettier-sql';\n\nconst query = `SELECT id, name, age FROM users WHERE age > 18 ORDER BY name`;\nconst formatted = format(query, {\n  language: 'postgresql',\n  uppercase: true,\n  indent: '  ',\n  linesBetweenQueries: 1,\n});\nconsole.log(formatted);\n// Output:\n// SELECT\n//   id,\n//   name,\n//   age\n// FROM\n//   users\n// WHERE\n//   age > 18\n// ORDER BY\n//   name","lang":"typescript","description":"Formats a PostgreSQL query with uppercase keywords, two-space indentation, and one line between queries."},"warnings":[{"fix":"Upgrade Node to >=14 and change import from default to named.","message":"v5 drops support for Node < 14 and removes default export (use named { format }).","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Replace indent_width: 4 with indent: '    '","message":"Config option 'indent_width' is deprecated; use 'indent' with string value instead.","severity":"deprecated","affected_versions":">=4.0.0"},{"fix":"Wrap numeric placeholders in quotes: params: { foo: \"'42'\" }","message":"Placeholder params must be strings; passing numbers without quotes may cause unexpected replacements.","severity":"gotcha","affected_versions":"*"},{"fix":"Use lowercase dialect names: sql, mysql, postgresql, etc.","message":"CLI flag --language is case-sensitive; 'sql' works but 'SQL' throws error.","severity":"gotcha","affected_versions":"*"},{"fix":"Upgrade to 5.1.0+ for improved handling of DISTINCT ON.","message":"Formatting may remove/reorder columns in SELECT DISTINCT ON (PostgreSQL) incorrectly.","severity":"gotcha","affected_versions":"<5.1.0"}],"env_vars":null,"search_vec":"'12':18 'bigqueri':23 'cli':48 'consider':38 'control':56 'depend':62 'dialect':19,53 'differenti':51 'diverg':37 'extens':52 'format':69 'formatt':68 'includ':20,65 'javascript':8,66 'key':50 'librari':9,34 'mysql':21,74 'n1ql':70 'npm':42 'offer':44 'php':33 'placehold':57 'port':30 'postgresql':22 'pretti':12 'prettier':1,3 'pretty-print':11 'print':13 'programmat':46 'queri':15 'redshift':71 'regular':40 'releas':39 'replac':58 'runtim':61 'spark':25,72 'sql':2,4,14,67 'start':27 'support':17,54 'type':63 'typescript':75 'uppercase/lowercase':55 'usag':49 'v5.1.1':5 'via':41 'whitespac':73 'zero':60","created_at":"2026-06-05T17:01:02.457707+00:00","updated_at":"2026-06-05T17:01:02.457707+00:00","problems":[{"fix":"Use --config config.json (file path) not --config '{ \"key\": \"value\" }'","cause":"Passing a JavaScript object instead of JSON string to CLI --config","error":"SyntaxError: Unexpected token o in JSON at position 1"},{"fix":"Use import { format } from 'prettier-sql'","cause":"Importing default export in ESM instead of named export { format }","error":"TypeError: format is not a function"},{"fix":"Use valid lowercase dialect: sql, mysql, postgresql, etc.","cause":"Using non-standard dialect name (e.g., 'Standard SQL' instead of 'sql')","error":"Error: Unknown dialect 'Standard SQL'"},{"fix":"Run npm install prettier-sql and ensure import path matches package name.","cause":"Package not installed or import path incorrect in bundler","error":"Module not found: Can't resolve 'prettier-sql' in '/path/to/project'"}],"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/inferrinizzard/prettier-sql#readme","github":"https://github.com/inferrinizzard/prettier-sql","docs":null,"changelog":null,"pypi":null,"npm":"prettier-sql","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}}