{"id":20431,"library":"prettier-plugin-sql-cst","title":"prettier-plugin-sql-cst","description":"A Prettier plugin for SQL that uses sql-parser-cst and the actual Prettier formatting algorithm (Wadler-Leijen). It adapts formatting based on expression length, sticking to one style with minimal configuration options. The plugin supports multiple SQL dialects: SQLite, BigQuery, PostgreSQL, MySQL, and MariaDB (some experimental). It parses and formats SQL code inside CREATE FUNCTION/PROCEDURE bodies (PostgreSQL). Current stable version is 0.19.3, with semi-regular releases (every few weeks). TypeScript types are shipped. Key differentiators vs other SQL formatters: uses Prettier's algorithmic line splitting for consistency, preserves syntax elements, and formats embedded languages.","status":"active","version":"0.19.3","language":"javascript","source_language":"en","source_url":"https://github.com/nene/prettier-plugin-sql-cst","tags":["javascript","prettier","sql","plugin","typescript"],"install":[{"cmd":"npm install prettier-plugin-sql-cst","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-sql-cst","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-sql-cst","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency – the plugin requires Prettier to be installed","package":"prettier","optional":false}],"imports":[{"note":"ESM-only since v0.19.3 – the package is compiled into a single ESM .js file. No default export actually exists; you use the package implicitly via Prettier's plugin resolution. Do not import directly.","wrong":"const prettierPluginSqlCst = require('prettier-plugin-sql-cst')","symbol":"default","correct":"import prettierPluginSqlCst from 'prettier-plugin-sql-cst'"},{"note":"sqlite is a parser name string, not an export. It is used as the parser option in Prettier configuration.","wrong":"import { sqlite } from 'prettier-plugin-sql-cst'","symbol":"sqlite","correct":"// In .prettierrc: { \"plugins\": [\"prettier-plugin-sql-cst\"], \"overrides\": [{ \"files\": [\"*.sql\"], \"options\": { \"parser\": \"sqlite\" } }] }"},{"note":"bigquery is a parser name string, not an export. Use in parser option.","wrong":"import bigquery from 'prettier-plugin-sql-cst'","symbol":"bigquery","correct":"// In .prettierrc: { \"plugins\": [\"prettier-plugin-sql-cst\"], \"overrides\": [{ \"files\": [\"*.sql\"], \"options\": { \"parser\": \"bigquery\" } }] }"}],"quickstart":{"code":"// Install dependencies\n// npm install --save-dev prettier prettier-plugin-sql-cst\n\n// Create a .prettierrc.json file:\n{\n  \"plugins\": [\"prettier-plugin-sql-cst\"],\n  \"overrides\": [\n    {\n      \"files\": [\"*.sql\"],\n      \"options\": { \"parser\": \"sqlite\" }\n    }\n  ]\n}\n\n// Then create a SQL file (e.g., test.sql):\nSELECT a, b, c FROM tbl WHERE x > 10;\n\n// Run prettier:\n// npx prettier --write test.sql\n\n// Output:\nSELECT a, b, c\nFROM tbl\nWHERE x > 10;","lang":"javascript","description":"Shows how to install the plugin, configure it in .prettierrc.json, and format a basic SQL query."},"warnings":[{"fix":"Review formatted output after upgrade. No manual fix available.","message":"v0.19.0+ - Upgraded sql-parser-cst to 0.39.0, possibly changing AST for some SQL constructs. Formatting may change.","severity":"breaking","affected_versions":">=0.19.0"},{"fix":"Add sqlTypeCase: 'lower' and sqlIdentifierCase: 'lower' to config for PostgreSQL if lowercase types are desired.","message":"v0.17.0+ - PostgreSQL builtin data type names now formatted in upper case by default. sqlTypeCase, sqlIdentifierCase, sqlFunctionCase options added.","severity":"breaking","affected_versions":">=0.17.0"},{"fix":"Ensure project is ESM, or use a dynamic import: const prettierPluginSqlCst = await import('prettier-plugin-sql-cst'). Then use via Prettier's plugin system, not direct import.","message":"v0.19.3 - Package compiled into a single ESM .js file. Breaking for CommonJS consumers.","severity":"breaking","affected_versions":">=0.19.3"},{"fix":"Set sqlCanonicalSyntax: false if preserving case is important, or accept uppercase keywords.","message":"`preserve` case option is incompatible with `sqlCanonicalSyntax: true` – added keywords like AS will always be uppercase.","severity":"gotcha","affected_versions":"<0.18.0? (present in release notes)"},{"fix":"Use sqlite or bigquery parsers for production; test with your SQL dialect thoroughly.","message":"PostgreSQL, MySQL, MariaDB parsers are experimental – expect crashes on complex queries.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use import() or ensure your project is configured as ESM. Alternatively, downgrade to v0.19.2 or earlier. Or use Prettier's CLI which handles plugins internally.","cause":"The plugin is ESM-only since v0.19.3, but CommonJS require() is used.","error":"Error: Cannot find module 'prettier-plugin-sql-cst' require() of ES Module"},{"fix":"Do not import or call directly. Use the plugin via Prettier's plugin configuration in .prettierrc or CLI --plugin option.","cause":"Direct import of the module and calling it as a function.","error":"TypeError: prettier-plugin-sql-cst.default is not a function"},{"fix":"Set parser in .prettierrc overrides or use --parser flag: prettier --plugin prettier-plugin-sql-cst --parser sqlite myfile.sql","cause":"Prettier cannot auto-detect SQL dialect; no 'parser' option set.","error":"Error: No parser could be inferred for file: myfile.sql"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}