{"id":21319,"date":"2024-01-02T07:24:27","date_gmt":"2024-01-02T07:24:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21319\/"},"modified":"2024-11-14T10:36:50","modified_gmt":"2024-11-14T02:36:50","slug":"how-to-fix-postgresql-error-code-22p05-untranslatable_character","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21319\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-22p05-untranslatable_character-xPErciyJST\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u529f\u80fd\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u8cc7\u6599\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u88ab\u5168\u7403\u958b\u767c\u8005\u548c\u4f01\u696d\u5ee3\u6cdb\u4f7f\u7528\u3002\u7136\u800c\uff0c\u8207\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0c\u5b83\u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u932f\u8aa4\uff0c\u5f71\u97ff\u5176\u529f\u80fd\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u542b\u7fa9\u4e26\u63d0\u4f9b\u89e3\u6c7a\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"understanding-the-postgresql-error-code-22p05-untranslatable_character-xPErciyJST\">\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character \u6703\u5728\u5617\u8a66\u5c07\u7121\u6cd5\u8f49\u63db\u70ba\u76ee\u6a19\u5b57\u7b26\u96c6\u7684\u503c\u63d2\u5165\u6216\u66f4\u65b0\u5230\u6b04\u4f4d\u6642\u51fa\u73fe\u3002\u6b64\u932f\u8aa4\u901a\u5e38\u5728\u63d2\u5165\u6216\u66f4\u65b0\u7684\u6578\u64da\u5b57\u7b26\u96c6\u8207\u6b04\u4f4d\u5b9a\u7fa9\u7684\u5b57\u7b26\u96c6\u4e0d\u5339\u914d\u6642\u767c\u751f\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u6b04\u4f4d\u5b9a\u7fa9\u7684\u5b57\u7b26\u96c6\u662f &#8216;UTF8&#8217;\uff0c\u800c\u60a8\u5617\u8a66\u63d2\u5165\u7684\u6578\u64da\u5305\u542b\u4e0d\u652f\u63f4 &#8216;UTF8&#8217; \u5b57\u7b26\u96c6\u7684\u5b57\u7b26\uff0c\u5c31\u6703\u51fa\u73fe 22P05 \u932f\u8aa4\u3002<\/p>\n<h2 id=\"steps-to-fix-the-postgresql-error-code-22p05-untranslatable_character-xPErciyJST\">\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character \u7684\u6b65\u9a5f<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character\uff0c\u9700\u627e\u51fa\u932f\u8aa4\u7684\u6839\u6e90\u4e26\u63a1\u53d6\u76f8\u61c9\u7684\u884c\u52d5\u3002\u4ee5\u4e0b\u662f\u89e3\u6c7a\u6b64\u932f\u8aa4\u7684\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"step-1-identify-the-affected-column-xPErciyJST\">\u6b65\u9a5f 1\uff1a\u8b58\u5225\u53d7\u5f71\u97ff\u7684\u6b04\u4f4d<\/h3>\n<p>\u9996\u5148\uff0c\u78ba\u5b9a\u5c0e\u81f4\u932f\u8aa4\u7684\u6b04\u4f4d\u3002\u60a8\u53ef\u4ee5\u6aa2\u67e5\u932f\u8aa4\u8a0a\u606f\u6216\u5f15\u767c\u932f\u8aa4\u7684\u67e5\u8a62\uff0c\u5c0b\u627e\u932f\u8aa4\u8a0a\u606f\u6216\u67e5\u8a62\u8a9e\u53e5\u4e2d\u63d0\u5230\u7684\u6b04\u4f4d\u540d\u7a31\u3002<\/p>\n<h3 id=\"step-2-check-the-character-set-of-the-column-xPErciyJST\">\u6b65\u9a5f 2\uff1a\u6aa2\u67e5\u6b04\u4f4d\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u8b58\u5225\u51fa\u53d7\u5f71\u97ff\u7684\u6b04\u4f4d\u5f8c\uff0c\u6aa2\u67e5\u8a72\u6b04\u4f4d\u5b9a\u7fa9\u7684\u5b57\u7b26\u96c6\u3002\u60a8\u53ef\u4ee5\u67e5\u8a62 PostgreSQL \u7cfb\u7d71\u76ee\u9304\u8868 &#8216;pg_attribute&#8217;\uff0c\u6216\u4f7f\u7528 &#8216;psql&#8217; \u547d\u4ee4\u884c\u5de5\u5177\u4f86\u5b8c\u6210\u6b64\u64cd\u4f5c\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u82e5\u6b04\u4f4d\u540d\u7a31\u70ba &#8216;description&#8217; \u4e26\u4f4d\u65bc &#8216;products&#8217; \u8868\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\u6aa2\u67e5\u5b57\u7b26\u96c6\uff1a<\/p>\n<pre><code>SELECT attname, atttypid, atttypmod FROM pg_attribute WHERE attrelid = 'products'::regclass AND attname = 'description';\r\n<\/code><\/pre>\n<p>\u6b64\u67e5\u8a62\u5c07\u8fd4\u56de\u6709\u95dc\u6b04\u4f4d\u7684\u4fe1\u606f\uff0c\u5305\u62ec\u5b57\u7b26\u96c6\uff08atttypid\uff09\u548c\u5176\u4fee\u98fe\u7b26\uff08atttypmod\uff09\u3002<\/p>\n<h3 id=\"step-3-verify-the-character-set-of-the-data-xPErciyJST\">\u6b65\u9a5f 3\uff1a\u9a57\u8b49\u6578\u64da\u7684\u5b57\u7b26\u96c6<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u9a57\u8b49\u60a8\u5617\u8a66\u63d2\u5165\u6216\u66f4\u65b0\u7684\u6578\u64da\u5b57\u7b26\u96c6\uff0c\u78ba\u4fdd\u6578\u64da\u8207\u6b04\u4f4d\u5b9a\u7fa9\u7684\u5b57\u7b26\u96c6\u76f8\u5bb9\u3002<\/p>\n<p>\u5982\u679c\u6578\u64da\u5305\u542b\u6b04\u4f4d\u5b57\u7b26\u96c6\u4e0d\u652f\u63f4\u7684\u5b57\u7b26\uff0c\u60a8\u9700\u8981\u4fee\u6539\u6578\u64da\u6216\u66f4\u6539\u6b04\u4f4d\u7684\u5b57\u7b26\u96c6\u3002<\/p>\n<h3 id=\"step-4-modify-the-data-or-change-the-character-set-xPErciyJST\">\u6b65\u9a5f 4\uff1a\u4fee\u6539\u6578\u64da\u6216\u66f4\u6539\u5b57\u7b26\u96c6<\/h3>\n<p>\u5982\u679c\u6578\u64da\u5305\u542b\u7121\u6cd5\u8f49\u63db\u7684\u5b57\u7b26\uff0c\u60a8\u53ef\u4ee5\u4fee\u6539\u6578\u64da\u4ee5\u522a\u9664\u6216\u66ff\u63db\u9019\u4e9b\u5b57\u7b26\uff0c\u6216\u8005\u66f4\u6539\u6b04\u4f4d\u7684\u5b57\u7b26\u96c6\u4ee5\u652f\u63f4\u8a72\u6578\u64da\u3002<\/p>\n<p>\u8981\u4fee\u6539\u6578\u64da\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b57\u4e32\u8655\u7406\u51fd\u6578\u6216\u6b63\u5247\u8868\u9054\u5f0f\u4f86\u522a\u9664\u6216\u66ff\u63db\u7121\u6cd5\u8f49\u63db\u7684\u5b57\u7b26\u3002\u6216\u8005\uff0c\u60a8\u4e5f\u53ef\u4ee5\u5c07\u6b04\u4f4d\u7684\u5b57\u7b26\u96c6\u66f4\u6539\u70ba\u66f4\u9069\u5408\u7684\u5b57\u7b26\u96c6\uff0c\u4ee5\u652f\u63f4\u8a72\u6578\u64da\u3002<\/p>\n<h3 id=\"step-5-test-and-validate-xPErciyJST\">\u6b65\u9a5f 5\uff1a\u6e2c\u8a66\u4e26\u9a57\u8b49<\/h3>\n<p>\u5728\u505a\u51fa\u5fc5\u8981\u7684\u66f4\u6539\u5f8c\uff0c\u91cd\u8a66\u5f15\u767c\u932f\u8aa4\u7684\u67e5\u8a62\u6216\u64cd\u4f5c\uff0c\u78ba\u4fdd PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character \u5df2\u89e3\u6c7a\u3002\u9a57\u8b49\u6578\u64da\uff0c\u78ba\u4fdd\u5176\u80fd\u5920\u6b63\u78ba\u63d2\u5165\u6216\u66f4\u65b0\u4e14\u4e0d\u518d\u51fa\u73fe\u932f\u8aa4\u3002<\/p>\n<h2 id=\"summary-xPErciyJST\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22P05 &#8211; untranslatable_character \u53ef\u4ee5\u901a\u904e\u8b58\u5225\u53d7\u5f71\u97ff\u7684\u6b04\u4f4d\u3001\u6aa2\u67e5\u5176\u5b57\u7b26\u96c6\u3001\u9a57\u8b49\u6578\u64da\u7684\u5b57\u7b26\u96c6\u3001\u4fee\u6539\u6578\u64da\u6216\u66f4\u6539\u5b57\u7b26\u96c6\uff0c\u4ee5\u53ca\u6e2c\u8a66\u8b8a\u66f4\u4f86\u89e3\u6c7a\u3002\u901a\u904e\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u78ba\u4fdd PostgreSQL \u6578\u64da\u5eab\u7684\u9806\u66a2\u904b\u884c\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc VPS \u8a17\u7ba1\u53ca\u5176\u5982\u4f55\u70ba\u60a8\u7684\u696d\u52d9\u5e36\u4f86\u597d\u8655\uff0c\u8acb\u8a2a\u554f <a href=\"https:\/\/server.hk\">Server.HK<\/a>\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-21319","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21319","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=21319"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21319\/revisions"}],"predecessor-version":[{"id":24195,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21319\/revisions\/24195"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21319"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21319"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21319"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}