{"id":21398,"date":"2024-01-02T08:43:21","date_gmt":"2024-01-02T08:43:21","guid":{"rendered":"https:\/\/server.hk\/blog\/21398\/"},"modified":"2024-11-14T10:35:11","modified_gmt":"2024-11-14T02:35:11","slug":"how-to-fix-postgresql-error-code-42846-cannot_coerce","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21398\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce"},"content":{"rendered":"<h1>\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce<\/h1>\n<p>\u7c21\u4ecb\uff1aPostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u958b\u767c\u4eba\u54e1\u548c\u4f01\u696d\u3002\u7136\u800c\uff0c\u50cf\u6240\u6709\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u963b\u7919\u5176\u5e73\u7a69\u904b\u884c\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u8a72\u932f\u8aa4\u7684\u6210\u56e0\u4e26\u63d0\u4f9b\u9010\u6b65\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2>\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce \u767c\u751f\u5728\u5617\u8a66\u5c07\u4e00\u7a2e\u6578\u64da\u985e\u578b\u8f49\u63db\u70ba\u53e6\u4e00\u7a2e\u6642\uff0c\u4f46\u7531\u65bc\u6578\u64da\u985e\u578b\u4e0d\u517c\u5bb9\uff0c\u8f49\u63db\u7121\u6cd5\u9032\u884c\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u5728\u57f7\u884c\u6578\u64da\u63d2\u5165\u3001\u66f4\u65b0\u6216\u6bd4\u8f03\u7b49\u64cd\u4f5c\u6642\u51fa\u73fe\u3002<\/p>\n<h2>\u932f\u8aa4\u7684\u6210\u56e0<\/h2>\n<ol>\n<li><strong>\u4e0d\u517c\u5bb9\u7684\u6578\u64da\u985e\u578b\uff1a<\/strong>\u9019\u500b\u932f\u8aa4\u6700\u5e38\u898b\u7684\u539f\u56e0\u662f\u5617\u8a66\u5728\u4e0d\u517c\u5bb9\u7684\u985e\u578b\u4e4b\u9593\u9032\u884c\u6578\u64da\u8f49\u63db\uff0c\u4f8b\u5982\u8a66\u5716\u5c07\u5b57\u7b26\u4e32\u8f49\u63db\u70ba\u6574\u6578\u6216\u53cd\u4e4b\u3002<\/li>\n<li><strong>\u7f3a\u5931\u6216\u4e0d\u6b63\u78ba\u7684\u8f49\u63db\uff1a<\/strong>\u5982\u679c\u6578\u64da\u5eab\u6a21\u5f0f\u4e2d\u672a\u5b9a\u7fa9\u5fc5\u8981\u7684\u8f49\u63db\uff0cPostgreSQL \u53ef\u80fd\u7121\u6cd5\u57f7\u884c\u6240\u9700\u7684\u6578\u64da\u985e\u578b\u8f49\u63db\uff0c\u5f9e\u800c\u5c0e\u81f4 cannot_coerce \u932f\u8aa4\u3002<\/li>\n<li><strong>\u8a9e\u6cd5\u4e0d\u6b63\u78ba\uff1a<\/strong>SQL \u67e5\u8a62\u6216\u8a9e\u53e5\u4e2d\u7684\u8a9e\u6cd5\u932f\u8aa4\u4e5f\u6703\u89f8\u767c\u6b64\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u4e0d\u6b63\u78ba\u7684\u51fd\u6578\u6216\u904b\u7b97\u7b26\u9032\u884c\u6578\u64da\u985e\u578b\u8f49\u63db\u3002<\/li>\n<\/ol>\n<h2>\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce \u7684\u65b9\u6848<\/h2>\n<ol>\n<li><strong>\u6aa2\u67e5\u6578\u64da\u985e\u578b\uff1a<\/strong>\u6aa2\u67e5\u5f15\u767c\u932f\u8aa4\u7684\u64cd\u4f5c\u4e2d\u6d89\u53ca\u7684\u5217\u7684\u6578\u64da\u985e\u578b\u3002\u78ba\u4fdd\u6578\u64da\u985e\u578b\u517c\u5bb9\u4e26\u4e14\u53ef\u4ee5\u76f8\u4e92\u8f49\u63db\u3002\u5982\u6709\u5fc5\u8981\uff0c\u4fee\u6539\u6578\u64da\u985e\u578b\u6216\u4f7f\u7528\u9069\u7576\u7684\u51fd\u6578\u5982 <code>CAST<\/code> \u6216 <code>::<\/code> \u9032\u884c\u986f\u5f0f\u985e\u578b\u8f49\u63db\u3002<\/li>\n<li><strong>\u5b9a\u7fa9\u8f49\u63db\uff1a<\/strong>\u5982\u679c\u7f3a\u5c11\u6240\u9700\u7684\u8f49\u63db\uff0c\u5247\u4f7f\u7528 <code>CREATE CAST<\/code> \u547d\u4ee4\u5728\u6578\u64da\u5eab\u6a21\u5f0f\u4e2d\u5b9a\u7fa9\u5b83\u5011\u3002\u9019\u5c07\u4f7f PostgreSQL \u5728\u9700\u8981\u6642\u80fd\u5920\u57f7\u884c\u5fc5\u8981\u7684\u8f49\u63db\u3002<\/li>\n<li><strong>\u9a57\u8b49\u8a9e\u6cd5\uff1a<\/strong>\u4ed4\u7d30\u6aa2\u67e5\u60a8\u7684 SQL \u67e5\u8a62\u6216\u8a9e\u53e5\u7684\u8a9e\u6cd5\u3002\u78ba\u4fdd\u7528\u65bc\u6578\u64da\u985e\u578b\u8f49\u63db\u7684\u51fd\u6578\u3001\u904b\u7b97\u7b26\u548c\u8a9e\u6cd5\u6b63\u78ba\u3002\u8acb\u53c3\u8003 PostgreSQL \u6587\u6a94\u4ee5\u7372\u53d6\u9069\u7576\u7684\u8a9e\u6cd5\u548c\u7528\u6cd5\u3002<\/li>\n<li><strong>\u4f7f\u7528\u986f\u5f0f\u8f49\u63db\uff1a<\/strong>\u8207\u5176\u4f9d\u8cf4\u96b1\u5f0f\u985e\u578b\u8f49\u63db\uff0c\u4e0d\u5982\u4f7f\u7528 <code>CAST<\/code> \u6216 <code>::<\/code> \u7b49\u51fd\u6578\u986f\u5f0f\u8f49\u63db\u6578\u64da\u985e\u578b\u3002\u9019\u78ba\u4fdd\u8f49\u63db\u6309\u9810\u671f\u57f7\u884c\uff0c\u4e26\u6e1b\u5c11\u9047\u5230 cannot_coerce \u932f\u8aa4\u7684\u6a5f\u6703\u3002<\/li>\n<li><strong>\u8abf\u8a66\u5de5\u5177\uff1a<\/strong>\u5229\u7528 PostgreSQL \u7684\u8abf\u8a66\u5de5\u5177\uff0c\u4f8b\u5982 <code>EXPLAIN<\/code> \u547d\u4ee4\uff0c\u5206\u6790\u67e5\u8a62\u7684\u57f7\u884c\u8a08\u5283\u3002\u9019\u6709\u52a9\u65bc\u8b58\u5225\u6578\u64da\u985e\u578b\u8f49\u63db\u7684\u6f5b\u5728\u554f\u984c\uff0c\u4e26\u63d0\u4f9b\u512a\u5316\u67e5\u8a62\u7684\u898b\u89e3\u3002<\/li>\n<\/ol>\n<h2>\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42846 &#8211; cannot_coerce \u53ef\u80fd\u6703\u5728\u5617\u8a66\u8f49\u63db\u4e0d\u517c\u5bb9\u7684\u6578\u64da\u985e\u578b\u6216\u7f3a\u5c11\u5fc5\u8981\u7684\u8f49\u63db\u6642\u9047\u5230\u3002\u901a\u904e\u4ed4\u7d30\u6aa2\u67e5\u6578\u64da\u985e\u578b\u3001\u5b9a\u7fa9\u8f49\u63db\u3001\u9a57\u8b49\u8a9e\u6cd5\u3001\u4f7f\u7528\u986f\u5f0f\u8f49\u63db\u4ee5\u53ca\u5229\u7528\u8abf\u8a66\u5de5\u5177\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u89e3\u6c7a\u6b64\u932f\u8aa4\uff0c\u78ba\u4fdd PostgreSQL \u6578\u64da\u5eab\u7684\u5e73\u7a69\u904b\u884c\u3002<\/p>\n<p>\u5982\u9700\u53ef\u9760\u4e14\u9ad8\u6548\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e Server.HK\u3002\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u8a17\u7ba1\u670d\u52d9\u70ba\u904b\u884c PostgreSQL \u548c\u5176\u4ed6\u61c9\u7528\u7a0b\u5e8f\u63d0\u4f9b\u4e86\u7406\u60f3\u74b0\u5883\u3002\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u6709\u95dc\u6211\u5011\u8a17\u7ba1\u8a08\u5283\u548c\u529f\u80fd\u7684\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u5fa9 PostgreSQL &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-21398","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=21398"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21398\/revisions"}],"predecessor-version":[{"id":24095,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21398\/revisions\/24095"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}