Skip to main content
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:
The statement succeeds, but only the engine setting is kept:
An insert with a duplicated path still fails:

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:

How to tell which kind a setting is

Query settings are listed in system.settings, and MergeTree settings in system.merge_tree_settings:
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:
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:
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.
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.