> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Why a query setting in CREATE TABLE ... SETTINGS has no effect on later inserts

> A query setting in the SETTINGS clause of CREATE TABLE applies only to the CREATE statement and is not stored in the table. Learn where to set it so that inserts use it.

The `SETTINGS` clause of `CREATE TABLE` accepts two kinds of settings: settings of the table engine, which are stored in the table definition, and query settings, which apply to the `CREATE` statement itself and are then forgotten. A query setting written there does not become a property of the table, so later `INSERT` and `SELECT` queries do not see it. Set it on the query, the session, the user, or a settings profile instead.

## Example

The table below is created with one `MergeTree` setting (`index_granularity`) and one query setting (`type_json_skip_duplicated_paths`), with the intention that inserts into this table skip duplicated JSON paths:

```sql theme={null}
CREATE TABLE events
(
    id UInt64,
    payload JSON
)
ENGINE = MergeTree
ORDER BY id
SETTINGS index_granularity = 4096, type_json_skip_duplicated_paths = 1;

SHOW CREATE TABLE events;
```

The statement succeeds, but only the engine setting is kept:

```text theme={null}
CREATE TABLE default.events
(
    `id` UInt64,
    `payload` JSON
)
ENGINE = MergeTree
ORDER BY id
SETTINGS index_granularity = 4096
```

An insert with a duplicated path still fails:

```sql theme={null}
INSERT INTO events VALUES (1, '{"color": "red", "color": "blue"}');
```

```text theme={null}
Code: 117. DB::Exception: Cannot insert data into JSON column: Duplicate path found during parsing JSON object: color. You can enable setting type_json_skip_duplicated_paths to skip duplicated paths during insert: ... (INCORRECT_DATA)
```

## Why this happens

When ClickHouse runs a `CREATE TABLE` statement, it looks at every name in the `SETTINGS` clause:

* A setting of the table engine is stored with the table and shows up in `SHOW CREATE TABLE`.
* A query setting is applied to the `CREATE` statement and removed from the table definition. This is what lets you write, for example, `SETTINGS allow_suspicious_low_cardinality_types = 1` to permit a column type that the `CREATE` would otherwise reject.
* A name that is neither is rejected. For a `MergeTree` table the error is `UNKNOWN_SETTING`.

A table has no place to store query settings, so nothing carries the setting over to later queries.

The same name in `ALTER TABLE ... MODIFY SETTING` is rejected, because that statement accepts only engine settings:

```sql theme={null}
ALTER TABLE events MODIFY SETTING type_json_skip_duplicated_paths = 1;
```

```text theme={null}
Code: 115. DB::Exception: Unknown setting 'type_json_skip_duplicated_paths'. (UNKNOWN_SETTING)
```

## How to tell which kind a setting is

Query settings are listed in `system.settings`, and `MergeTree` settings in `system.merge_tree_settings`:

```sql theme={null}
SELECT 'query setting' AS kind, name
FROM system.settings
WHERE name = 'type_json_skip_duplicated_paths'
UNION ALL
SELECT 'MergeTree setting' AS kind, name
FROM system.merge_tree_settings
WHERE name = 'type_json_skip_duplicated_paths';
```

```text theme={null}
   ┌─kind──────────┬─name────────────────────────────┐
1. │ query setting │ type_json_skip_duplicated_paths │
   └───────────────┴─────────────────────────────────┘
```

A few names, such as `parts_to_throw_insert`, exist in both tables. In `CREATE TABLE ... SETTINGS` they are treated as engine settings and stored.

To see what was stored for a table, run `SHOW CREATE TABLE` or read `create_table_query` from `system.tables`.

## Where to put a query setting

On the `INSERT` statement. The `SETTINGS` clause goes before `VALUES`, `FORMAT` or `SELECT`:

```sql theme={null}
INSERT INTO events SETTINGS type_json_skip_duplicated_paths = 1 VALUES (1, '{"color": "red", "color": "blue"}');

SELECT id, payload FROM events;
```

```text theme={null}
   ┌─id─┬─payload─────────┐
1. │  1 │ {"color":"red"} │
   └────┴─────────────────┘
```

Everything after `VALUES` is data. A `SETTINGS` clause written after the values is read as data too and fails with error 27, `CANNOT_PARSE_INPUT_ASSERTION_FAILED` (`Cannot parse input: expected '(' before: 'SETTINGS ...`).

On the user that inserts the data, or on a settings profile that is assigned to that user, so that every query of the user gets the setting. Either statement is enough:

```sql theme={null}
ALTER USER etl_user MODIFY SETTING type_json_skip_duplicated_paths = 1;

CREATE SETTINGS PROFILE etl_profile SETTINGS type_json_skip_duplicated_paths = 1 TO etl_user;
```

`ALTER USER ... MODIFY SETTING` changes one setting and keeps the others. `ALTER USER ... SETTINGS` replaces the whole list of settings of the user.

A settings profile affects only the users and roles it is assigned to, which is what the `TO` clause does. A profile created without `TO` changes nothing until you assign it, for example with `ALTER SETTINGS PROFILE etl_profile TO etl_user`. In both cases the user gets the setting in new sessions: a session that is already open keeps the old value, so reconnect before you check with `SELECT getSetting('type_json_skip_duplicated_paths')`.

For the session or the connection: run `SET type_json_skip_duplicated_paths = 1`, pass `--type_json_skip_duplicated_paths 1` to `clickhouse-client`, or add `type_json_skip_duplicated_paths=1` to the URL parameters of the HTTP interface.

> [!NOTE]
>
> `type_json_skip_duplicated_paths` keeps the first value of a duplicated path and drops the others without a warning, as the output above shows. Check that this is the value you want before you enable it for all inserts.

## Related pages

* [Query-level session settings](https://clickhouse.com/docs/concepts/features/configuration/settings/settings-query-level.md)
* [`MergeTree` table settings](https://clickhouse.com/docs/reference/settings/merge-tree-settings)
* [`type_json_skip_duplicated_paths`](https://clickhouse.com/docs/reference/settings/formats/type-json#type_json_skip_duplicated_paths)
* [How to configure settings for a user in ClickHouse](https://clickhouse.com/docs/resources/support-center/knowledge-base/configuration-settings/configure-a-user-setting.md)
