mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-18 05:32:52 +00:00
Introduce setting create_table_empty_primary_key_by_default
If set to true and the table of MergeTree family does not contain ORDER BY and PRIMARY KEY, then an empty tuple is used by default
This commit is contained in:
parent
8f9a227de1
commit
852d627f6a
@ -807,6 +807,7 @@ class IColumn;
|
||||
M(Bool, allow_create_index_without_type, false, "Allow CREATE INDEX query without TYPE. Query will be ignored. Made for SQL compatibility tests.", 0) \
|
||||
M(Bool, create_index_ignore_unique, false, "Ignore UNIQUE keyword in CREATE UNIQUE INDEX. Made for SQL compatibility tests.", 0) \
|
||||
M(Bool, print_pretty_type_names, false, "Print pretty type names in DESCRIBE query and toTypeName() function", 0) \
|
||||
M(Bool, create_table_empty_primary_key_by_default, false, "Allow to create *MergeTree tables with empty primary key when ORDER BY and PRIMARY KEY not specified", 0) \
|
||||
|
||||
// End of COMMON_SETTINGS
|
||||
// Please add settings related to formats into the FORMAT_FACTORY_SETTINGS, move obsolete settings to OBSOLETE_SETTINGS and obsolete format settings to OBSOLETE_FORMAT_SETTINGS.
|
||||
|
@ -535,9 +535,20 @@ static StoragePtr create(const StorageFactory::Arguments & args)
|
||||
args.storage_def->set(args.storage_def->order_by, args.storage_def->primary_key->clone());
|
||||
|
||||
if (!args.storage_def->order_by)
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"You must provide an ORDER BY or PRIMARY KEY expression in the table definition. "
|
||||
"If you don't want this table to be sorted, use ORDER BY/PRIMARY KEY ()");
|
||||
{
|
||||
if (args.getLocalContext()->getSettingsRef().create_table_empty_primary_key_by_default)
|
||||
{
|
||||
args.storage_def->set(args.storage_def->order_by, makeASTFunction("tuple"));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw Exception(ErrorCodes::BAD_ARGUMENTS,
|
||||
"You must provide an ORDER BY or PRIMARY KEY expression in the table definition. "
|
||||
"If you don't want this table to be sorted, use ORDER BY/PRIMARY KEY (). "
|
||||
"Otherwise, you can use the setting 'create_table_empty_primary_key_by_default' to "
|
||||
"automatically add an empty primary key to the table definition");
|
||||
}
|
||||
}
|
||||
|
||||
/// Get sorting key from engine arguments.
|
||||
///
|
||||
|
Loading…
Reference in New Issue
Block a user