# prettifySql() function · @imqueue/pg-prisma

Source: https://imqueue.org/api/pg-prisma/latest/pg-prisma.prettifysql/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/pg-prisma 1.0.1 — generated reference, not hand-written

Format a one-line SQL string so it is readable in a log.

**Signature:**

```typescript
export declare function prettifySql(sql: string): string;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| sql | string | A SQL statement, typically as captured by a query log. |


**Returns:**

string

The same statement across multiple indented lines.

## Remarks

Three passes: runs of whitespace collapse to single spaces, every major keyword is upper-cased and moved onto a new line, and continuation clauses (`AND`, `OR` and the `JOIN` family) are indented one level under the statement they belong to. Longer keywords are matched before their prefixes, so `WITH RECURSIVE` and `LEFT JOIN` survive intact rather than breaking at `WITH` and `JOIN`.

Purely cosmetic and deliberately not a SQL parser. Matching is a word-boundary regex over a fixed keyword list, which is why a keyword inside an identifier is left alone but a keyword inside a string literal is not — it will be upper-cased and broken like any other. Use it for logs, never to rewrite SQL you intend to execute.

## Example


```typescript
prettifySql('select id from "User" where active = $1');
// SELECT id
// FROM "User"
// WHERE active = $1
```

