{"id":5985,"date":"2021-05-17T17:11:24","date_gmt":"2021-05-17T09:11:24","guid":{"rendered":"https:\/\/www.gbase8.cn\/?p=5985"},"modified":"2021-05-18T10:40:06","modified_gmt":"2021-05-18T02:40:06","slug":"clickhouse-%e4%b8%bb%e9%94%ae%e6%88%96%e6%8e%92%e5%ba%8f%e9%94%ae%e4%b8%8d%e8%83%bd%e4%b8%banull%e7%9a%84%e6%8a%a5%e9%94%99%e5%92%8c%e8%a7%a3%e5%86%b3%e6%96%b9%e6%b3%95sorting-key-cannot-contain-nulla","status":"publish","type":"post","link":"https:\/\/www.gbase8.cn\/en\/5985","title":{"rendered":"Clickhouse \u4e3b\u952e\u6216\u6392\u5e8f\u952e\u4e0d\u80fd\u4e3anull\u7684\u62a5\u9519\u548c\u89e3\u51b3\u65b9\u6cd5Sorting key cannot contain nullable columns"},"content":{"rendered":"<p>\u9ed8\u8ba4Clickhouse\u7684\u6392\u5e8f\u952e\u548c\u4e3b\u952e\u662f\u4e0d\u5141\u8bb8null\u7684\uff0c\u5426\u5219\u4f1a\u62a5Sorting key cannot contain nullable columns\u7684\u9519\u8bef\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u5f3a\u884c\u8bbe\u7f6e\u5141\u8bb8\u4e3anull\uff0c\u4f46\u4e0d\u5efa\u8bae\u4f7f\u7528\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-6a2ab3afd6878\" 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-6a2ab3afd6878\"  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\/5985\/#%E5%BB%BA%E8%A1%A8%E8%AF%AD%E5%8F%A5%E5%92%8C%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\" >\u5efa\u8868\u8bed\u53e5\u548c\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\/5985\/#%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=\"%E5%BB%BA%E8%A1%A8%E8%AF%AD%E5%8F%A5%E5%92%8C%E6%8A%A5%E9%94%99%E6%A0%B7%E4%BE%8B\"><\/span>\u5efa\u8868\u8bed\u53e5\u548c\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 t2(id Nullable(int), name String)engine=MergeTree order by id;\r\n\r\nCREATE TABLE t2\r\n(\r\n    `id` Nullable(int),\r\n    `name` String\r\n)\r\nENGINE = MergeTree\r\nORDER BY id\r\n\r\nQuery id: 26906160-ea00-4d9b-ae18-d7d7e1307a19\r\n\r\n\r\n0 rows in set. Elapsed: 0.005 sec.\r\n\r\nReceived exception from server (version 21.4.5):\r\nCode: 44. DB::Exception: Received from localhost:9000. DB::Exception: Sorting key cannot contain nullable columns.\r\n\r\nlocalhost :)\r\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<pre class=\"wp-block-code\"><code>localhost :) create table t2(id Nullable(int), name String)engine=MergeTree order by id settings allow_nullable_key=1;\r\n\r\nCREATE TABLE t2\r\n(\r\n    `id` Nullable(int),\r\n    `name` String\r\n)\r\nENGINE = MergeTree\r\nORDER BY id\r\nSETTINGS allow_nullable_key = 1\r\n\r\nQuery id: 5bbf4418-3bf9-44eb-86df-b931796b68b8\r\n\r\nOk.\r\n\r\n0 rows in set. Elapsed: 0.018 sec.\r\nlocalhost :) insert into t2 values(1,'111'),(null,'NNN'),(2,'2222');\r\n\r\nINSERT INTO t2 VALUES\r\n\r\nQuery id: b5c5bb0d-3300-44bb-ac9b-06f3893177d9\r\n\r\nOk.\r\n\r\n3 rows in set. Elapsed: 0.021 sec.\r\n\r\nlocalhost :) select * from t2;\r\n\r\nSELECT *\r\nFROM t2\r\n\r\nQuery id: 40fd61ee-d00a-4793-b240-a5dde25e5de7\r\n\r\n\u250c\u2500\u2500\u2500id\u2500\u252c\u2500name\u2500\u2510\r\n\u2502    1 \u2502 111  \u2502\r\n\u2502    2 \u2502 2222 \u2502\r\n\u2502 \u1d3a\u1d41\u1d38\u1d38 \u2502 NNN  \u2502\r\n\u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2534\u2500\u2500\u2500\u2500\u2500\u2500\u2518\r\n\r\n3 rows in set. Elapsed: 0.018 sec.\r\n<\/code><\/pre>","protected":false},"excerpt":{"rendered":"<p>\u9ed8\u8ba4Clickhouse\u7684\u6392\u5e8f\u952e\u548c\u4e3b\u952e\u662f\u4e0d\u5141\u8bb8null\u7684\uff0c\u5426\u5219\u4f1a\u62a5Sorting key cannot contain nullable columns\u7684\u9519\u8bef\u4fe1\u606f\u3002\u53ef\u4ee5\u901a\u8fc7\u53c2\u6570\u5f3a\u884c\u8bbe\u7f6e\u5141\u8bb8\u4e3anull\uff0c\u4f46\u4e0d\u5efa\u8bae\u4f7f\u7528\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-5985","post","type-post","status-publish","format-standard","hentry","category-clickhouse"],"_links":{"self":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5985","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=5985"}],"version-history":[{"count":3,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5985\/revisions"}],"predecessor-version":[{"id":5988,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/posts\/5985\/revisions\/5988"}],"wp:attachment":[{"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/media?parent=5985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/categories?post=5985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gbase8.cn\/en\/wp-json\/wp\/v2\/tags?post=5985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}