{"id":5669,"date":"2021-04-27T13:11:05","date_gmt":"2021-04-27T05:11:05","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=5669"},"modified":"2021-05-18T10:44:39","modified_gmt":"2021-05-18T02:44:39","slug":"clickhouse-%e5%bb%ba%e8%a1%a8create-table-mergetree%e6%8a%a5%e9%94%99dbexception-storage-mergetree-requires-3-to-4-parameters","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/5669","title":{"rendered":"clickhouse \u5efa\u8868create table MergeTree\u62a5\u9519DB::Exception: Storage MergeTree requires 3 to 4 parameters"},"content":{"rendered":"<p>Clickhouse \u5728\u521b\u5efaMergeTree\u5f15\u64ce\u7684\u8868\u65f6\uff0c\u5fc5\u987b\u6307\u5b9a\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u5426\u5219\u4f1a\u62a5DB::Exception: Storage MergeTree requires 3 to 4 parameters\u7684\u9519\u8bef\u3002<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Directory Navigation<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2b94560a145\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2b94560a145\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.gbase8.cn\/en\/5669\/#%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\" >\u62a5\u9519\u6837\u4f8b<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.gbase8.cn\/en\/5669\/#%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\" >Solution<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\"><\/span>\u62a5\u9519\u6837\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost :) create table t1(id int, name varchar(100),birthday date)ENGINE = MergeTree();\nCREATE TABLE t1\n(\n    `id` int,\n    `name` varchar(100),\n    `birthday` date\n)\nENGINE = MergeTree\n\nQuery id: 6f3cbf90-2921-4eb8-b0e3-959b503bcb03\n0 rows in set. Elapsed: 0.059 sec.\nReceived exception from server (version 21.4.5):\nCode: 42. DB::Exception: Received from localhost:9000. DB::Exception: Storage MergeTree requires 3 to 4 parameters:\nname of column with date,\n&#91;sampling element of primary key],\nprimary key expression,\nindex granularity\n\nSyntax for the MergeTree table engine:\nCREATE TABLE &#91;IF NOT EXISTS] &#91;db.]table_name &#91;ON CLUSTER cluster]\n(\n    name1 &#91;type1] &#91;DEFAULT|MATERIALIZED|ALIAS expr1] &#91;TTL expr1],\n    name2 &#91;type2] &#91;DEFAULT|MATERIALIZED|ALIAS expr2] &#91;TTL expr2],\n    ...\n    INDEX index_name1 expr1 TYPE type1(...) GRANULARITY value1,\n    INDEX index_name2 expr2 TYPE type2(...) GRANULARITY value2\n) ENGINE = MergeTree()\nORDER BY expr\n&#91;PARTITION BY expr]\n&#91;PRIMARY KEY expr]\n&#91;SAMPLE BY expr]\n&#91;TTL expr &#91;DELETE|TO DISK 'xxx'|TO VOLUME 'xxx'], ...]\n&#91;SETTINGS name=value, ...]\n\nSee details in documentation: https:\/\/clickhouse.tech\/docs\/en\/engines\/table-engines\/mergetree-family\/mergetree\/. Other engines of the family support different syntax, see details in the corresponding documentation topics.\n\nIf you use the Replicated version of engines, see https:\/\/clickhouse.tech\/docs\/en\/engines\/table-engines\/mergetree-family\/replication\/.\n.\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88\"><\/span>Solution<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u6307\u5b9a\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u6bd4\u5982\u4e3b\u952e\u5217 primary key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>localhost :) create table t1(id int, name varchar(100),birthday date)ENGINE = MergeTree() primary key id;\n\nCREATE TABLE t1\n(\n    `id` int,\n    `name` varchar(100),\n    `birthday` date\n)\nENGINE = MergeTree\nPRIMARY KEY id\n\nQuery id: 5f8f94dc-3db7-429c-b954-32538c859095\n\nOk.\n\n0 rows in set. Elapsed: 0.057 sec.\n\nlocalhost :)\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>Clickhouse \u5728\u521b\u5efaMergeTree\u5f15\u64ce\u7684\u8868\u65f6\uff0c\u5fc5\u987b\u6307\u5b9a\u4e00\u4e9b\u5fc5\u8981\u7684\u53c2\u6570\uff0c\u5426\u5219\u4f1a\u62a5DB::Exception: Storage MergeTree requires 3 to 4 parameters\u7684\u9519\u8bef\u3002<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[86],"tags":[],"class_list":["post-5669","post","type-post","status-publish","format-standard","hentry","category-clickhouse"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/comments?post=5669"}],"version-history":[{"count":2,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5669\/revisions"}],"predecessor-version":[{"id":5672,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5669\/revisions\/5672"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=5669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=5669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=5669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}