# template

## Description

Literal row and result templates with indexed or named placeholders and a per-field escaping rule. Set template_row and, when required, template_result. Unmatched literal text is an input error.

The row separator is written between rows. The example has no trailing newline;
include a newline in the row or result template when one is required.

Input and output. Select it with `FORMAT template`. Names ignore ASCII case; use the snake_case name shown here.

A template combines literal bytes with zero-based positional or named placeholders. Each placeholder states an escaping rule for that field. template_result can wrap the rows and include result placeholders.

Literal separators must match on input. The row separator is written only between rows; any final newline must come from a literal in the row or result template.

```text
SELECT expressions FORMAT template;
INSERT INTO table [(columns)] [SETTINGS ...] FORMAT template
<data>
```

## Example usage

```sql
SELECT CAST(7 AS Int64) AS id, 'Ada' AS name SETTINGS template_row='${0:Raw}|${1:Raw}',template_row_separator='\n' FORMAT template;
```

```text
7|Ada
```

## Format settings

Use a statement `SETTINGS` clause; these options are not persisted by `SET`.

| Setting                         | Type     | Default | Meaning                                                                                                                |
| ------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------- |
| `snappy_mode`                   | `String` | `basic` | Read Snappy client files as basic (Hadoop blocks) or framed (standard streaming format).                               |
| `template_quote_large_integers` | `Bool`   | `0`     | Write integers of at least 64 bits as strings in JSON template fields; retained narrow types stay numeric.             |
| `template_result`               | `String` | `''`    | Literal result template; empty means `${data}`. Output supports data and rows; input may skip prefix or suffix fields. |
| `template_row`                  | `String` | `''`    | Literal row template with named or zero-based column placeholders and per-field escaping; empty requires an override.  |
| `template_row_separator`        | `String` | `\n`    | Text between template rows, excluding their own literals; never written after the final row.                           |
