{"id":20432,"library":"prettier-plugin-sql","title":"prettier-plugin-sql","description":"Prettier plugin for formatting SQL files and SQL-in-JS. Wraps sql-formatter and node-sql-parser to support 20+ dialects including BigQuery, PostgreSQL, MySQL, ClickHouse. Requires Prettier 3.0.3+ and Node 14.18+. Version 0.20.0 adds ClickHouse support. Plugin is under active development but stable for basic usage. Differentiator: integrates with prettier-plugin-embed for embedded SQL in tagged templates.","status":"active","version":"0.20.0","language":"javascript","source_language":"en","source_url":"https://github.com/un-ts/prettier","tags":["javascript","sql","big-query","db2","flink-sql","hive","maria-db","mysql","n1ql","typescript"],"install":[{"cmd":"npm install prettier-plugin-sql","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sql","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency (^3.0.3) required at runtime","package":"prettier","optional":false}],"imports":[{"note":"Not imported directly; Prettier discovers it when listed in plugins array.","wrong":"import prettierPluginSql from 'prettier-plugin-sql'","symbol":"prettier-plugin-sql","correct":"Prettier plugin loaded via plugins config in .prettierrc: { \"plugins\": [\"prettier-plugin-sql\"] }"},{"note":"Type only; erased at runtime. In CJS, use import() or require with .d.ts.","wrong":"const { SqlBaseOptions } = require('prettier-plugin-sql')","symbol":"SqlBaseOptions","correct":"import type { SqlBaseOptions } from 'prettier-plugin-sql'"},{"note":"For SQL-in-JS formatting, embed options come from a separate package.","wrong":"","symbol":"PrettierPluginEmbedOptions","correct":"import type { PrettierPluginEmbedOptions } from 'prettier-plugin-embed'"}],"quickstart":{"code":"// Install: npm i -D prettier prettier-plugin-sql\n// .prettierrc\n{\n  \"plugins\": [\"prettier-plugin-sql\"],\n  \"language\": \"postgresql\",\n  \"keywordCase\": \"upper\"\n}\n\n// Run: npx prettier --write db.sql\n// Before (db.sql):\n//   sELect  first_name,    species froM\n//    animals\n//          WhERE\n//   id = 1\n//\n// After:\n//   SELECT\n//     first_name,\n//     species\n//   FROM\n//     animals\n//   WHERE\n//     id = 1","lang":"typescript","description":"Basic setup: add plugin to .prettierrc, configure PostgreSQL dialect and uppercase keywords, format a SQL file."},"warnings":[{"fix":"Upgrade Prettier to ^3.0.3","message":"prettier-plugin-sql requires Prettier v3.0.3 or later","severity":"breaking","affected_versions":"<3.0.3"},{"fix":"Use require('prettier-plugin-sql').default or switch to ESM","message":"CommonJS named exports removed in v0.19.2; use default export for CJS","severity":"deprecated","affected_versions":">=0.19.2"},{"fix":"Set params: JSON.stringify({}) instead of params: {}","message":"Options like params, paramTypes, dialect must be JSON-stringified strings (JSOX). Passing objects will silently fail.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set formatter: 'sql-formatter' for full option support.","message":"When using node-sql-parser formatter, only a subset of sql-formatter options are available; language defaults to 'sql'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Upgrade to Node.js 16 or higher.","message":"Node.js v14 is EOL; future releases may drop support","severity":"deprecated","affected_versions":">=0.18.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install -D prettier prettier-plugin-sql","cause":"Plugin not installed or not in node_modules","error":"Cannot find module 'prettier-plugin-sql'"},{"fix":"Upgrade Prettier: npm install -D prettier@latest","cause":"Prettier version <3.0.3","error":"Error: Could not load plugin 'prettier-plugin-sql'"},{"fix":"Do not import; add to .prettierrc plugins array.","cause":"Importing directly instead of using Prettier plugin system","error":"Module not found: Can't resolve 'prettier-plugin-sql'"},{"fix":"Use formatter: 'sql-formatter' or ensure language is supported by node-sql-parser.","cause":"Using node-sql-parser with unsupported language/dialect","error":"TypeError: Cannot read properties of undefined (reading 'format')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}