sqlfmt is an opinionated Python-based command-line tool that automatically formats your dbt SQL files and other SQL statements. Similar to `black` for Python, it enforces a consistent style with minimal configuration, primarily line length. It is currently at version 0.29.0 and maintains an active release cadence with frequent updates.
pip install shandy-sqlfmtNo compatibility data collected yet for this library.
sqlfmt is primarily a command-line tool. The most common usage is to format files in a directory. It will exit with a non-zero code if files are not formatted when using `--check` or `--diff`.
Upgrade your Python environment to version 3.10 or higher. For example, using pyenv or updating your system Python.
Always use sqlfmt within a version-controlled project (e.g., Git) and commit your changes before running the formatter. Review the diffs carefully before accepting them.
Adjust any scripts or processes that consume `sqlfmt`'s stdout to account for the absence of the previously included extra trailing newline.
Understand that `sqlfmt` prioritizes consistency over customization. If its style does not align with your needs, consider alternatives or adapt your team to the `sqlfmt` style.
Activate your virtual environment if you used one for installation. Alternatively, ensure the directory containing the `sqlfmt` executable (e.g., `~/.local/bin` on Linux/macOS or `C:\Users\YourUser\AppData\Roaming\Python\Scripts` on Windows) is in your system's PATH, or run it using `python -m sqlfmt`.
Simplify the SQL statement causing the error or adjust it to be more standard. If using dbt/Jinja, try to isolate the problematic part or use `{# sqlfmt: off #}` and `{# sqlfmt: on #}` comments to exclude specific blocks from formatting. Ensure your `shandy-sqlfmt` version is up-to-date, as parsing capabilities are frequently improved.Run `sqlfmt .` (or `sqlfmt <target_files>`) without the `--check` flag to automatically format the files, then commit the changes.
Consult the `sqlfmt --help` output or the official documentation (on GitHub) for the correct and current command-line options.