# FORMAT

`FORMAT` chooses the encoding used for a query result. It is available through the native and HTTP server interfaces. The embedded `Connection` API returns typed values directly.

If no format is specified, the server uses `pretty_compact`.

## Syntax

```text
SELECT ... [SETTINGS setting = value, ...] FORMAT format_name
SELECT ... FORMAT format_name [SETTINGS setting = value, ...]
```

Format names are case-insensitive and use snake_case. For example, use `json_each_row`; `JSONEachRow` is not an alias.

`SETTINGS` in this context applies format options to one statement. It does not persist them as database settings. Each format's reference page lists its available options.

## Examples

### One JSON object per row

```sql
CREATE TABLE messages (id INTEGER, message TEXT);
INSERT INTO messages VALUES (1, 'hello'), (2, 'goodbye');
```

```sql
SELECT id, message
FROM messages
ORDER BY id
FORMAT json_each_row;
```

```text
{"id":1,"message":"hello"}
{"id":2,"message":"goodbye"}
```

### A custom CSV separator

```sql
SELECT 1 AS id, 'hello' AS message
SETTINGS csv_separator = ';'
FORMAT csv;
```

```text
1;"hello"
```

Formats can support input, output or both. An input-only format cannot encode a SELECT result. Use [`system.formats`](https://coordinatordb.com/docs/reference/system-tables/formats) to inspect directions, or browse the [format reference](https://coordinatordb.com/docs/reference/formats).

For `INSERT ... FORMAT`, place settings before the format name because the following bytes are input data. See [`INSERT INTO`](https://coordinatordb.com/docs/reference/statements/insert-into).
