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 oneMergeTree setting (index_granularity) and one query setting (type_json_skip_duplicated_paths), with the intention that inserts into this table skip duplicated JSON paths:
Why this happens
When ClickHouse runs aCREATE 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
CREATEstatement and removed from the table definition. This is what lets you write, for example,SETTINGS allow_suspicious_low_cardinality_types = 1to permit a column type that theCREATEwould otherwise reject. - A name that is neither is rejected. For a
MergeTreetable the error isUNKNOWN_SETTING.
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 insystem.settings, and MergeTree settings in system.merge_tree_settings:
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 theINSERT statement. The SETTINGS clause goes before VALUES, FORMAT or SELECT:
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.