https://github.com/cpg314/pg_ch_format
Format Postgres or Clickhouse SQL files.
https://github.com/cpg314/pg_ch_format
clickhouse formatter postgres rust
Last synced: 26 days ago
JSON representation
Format Postgres or Clickhouse SQL files.
- Host: GitHub
- URL: https://github.com/cpg314/pg_ch_format
- Owner: cpg314
- License: apache-2.0
- Created: 2024-05-01T19:22:44.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-02T19:48:53.000Z (about 2 years ago)
- Last Synced: 2025-10-25T09:36:01.493Z (8 months ago)
- Topics: clickhouse, formatter, postgres, rust
- Language: Rust
- Homepage: https://c.pgdm.ch/code
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pg_ch_format
The goals of that small tool are to:
- Allow running [`pg_format`](https://github.com/darold/pgFormatter/) or [`clickhouse-format`](https://clickhouse.com/docs/en/operations/utilites/clickhouse-format) on SQL files, detecting the dialect (Postgres or Clickhouse) automatically or through file extensions or annotations.
- Add a check mode to both, to verify in CI that files are properly formatted. See [this github issue](https://github.com/darold/pgFormatter/issues/137).
## Usage
```
Format Postgres or Clickhouse SQL files.
OUTPUT FORMAT
If the input is stdin (`-`), the formatted contents will be output on stdout.
Otherwise, a diff for the misformatted files is shown.
EXIT CODES
0: Success
1: Program error
2: Unformatted files
Usage: pg_ch_format [OPTIONS]
Arguments:
Folder, filename, or `-` to read from stdin
Options:
-i, --inplace
Rewrite the formatted files..
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
```
## Dialect detection
This is for now very primitive. You can also specify the dialect manually with
```sql
-- dialect=Clickhouse
-- or
-- dialect=Postgres
```
in your SQL file.
## Known issues
- A bug in `clickhouse-format` removes some inline comments (https://github.com/ClickHouse/ClickHouse/issues/62256)