{"id":21313,"date":"2024-01-02T07:18:27","date_gmt":"2024-01-02T07:18:27","guid":{"rendered":"https:\/\/server.hk\/blog\/21313\/"},"modified":"2024-11-14T10:36:57","modified_gmt":"2024-11-14T02:36:57","slug":"how-to-fix-postgresql-error-code-22024-unterminated_c_string","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21313\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-22024-unterminated_c_string-fAYDyCAaKj\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string<\/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\u5ee3\u6cdb\u61c9\u7528\u65bc\u5168\u7403\u7684\u958b\u767c\u8005\u548c\u4f01\u696d\u3002\u7136\u800c\uff0c\u8207\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u53ef\u80fd\u6703\u9047\u5230\u4e00\u4e9b\u932f\u8aa4\uff0c\u5f9e\u800c\u5f71\u97ff\u5176\u6b63\u5e38\u904b\u884c\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string\u3002\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u6210\u56e0\uff0c\u4e26\u63d0\u4f9b\u9010\u6b65\u89e3\u6c7a\u65b9\u6cd5\u3002<\/p>\n<h2 id=\"understanding-the-error-fAYDyCAaKj\">\u7406\u89e3\u932f\u8aa4<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string \u767c\u751f\u5728\u67e5\u8a62\u4e2d\u5b58\u5728\u672a\u7d50\u675f\u6216\u683c\u5f0f\u4e0d\u6b63\u78ba\u7684\u5b57\u4e32\u6642\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u662f\u56e0\u70ba\u5b57\u4e32\u5e38\u91cf\u6c92\u6709\u7528\u55ae\u5f15\u865f (&#8221;) \u5305\u88f9\u3002PostgreSQL \u5c07\u7528\u55ae\u5f15\u865f\u62ec\u8d77\u4f86\u7684\u5167\u5bb9\u8996\u70ba\u5b57\u4e32\u5e38\u91cf\uff0c\u5982\u679c\u5f15\u865f\u907a\u6f0f\u6216\u653e\u7f6e\u4e0d\u6b63\u78ba\uff0c\u4fbf\u6703\u5f15\u767c\u6b64\u932f\u8aa4\u3002<\/p>\n<h2 id=\"possible-causes-fAYDyCAaKj\">\u53ef\u80fd\u7684\u539f\u56e0<\/h2>\n<p>\u60a8\u53ef\u80fd\u9047\u5230 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string \u7684\u5e7e\u500b\u539f\u56e0\uff1a<\/p>\n<ul>\n<li><strong>\u7f3a\u5c11\u5f15\u865f\uff1a<\/strong>\u5fd8\u8a18\u5c07\u5b57\u4e32\u5e38\u91cf\u7528\u55ae\u5f15\u865f\u62ec\u8d77\u4f86\u6703\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u82e5\u60a8\u7684\u67e5\u8a62\u70ba <code>SELECT * FROM table WHERE name = John;<\/code> \u800c\u975e <code>SELECT * FROM table WHERE name = 'John';<\/code>\uff0c\u5247\u6703\u51fa\u73fe\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u5f15\u865f\u4e0d\u5e73\u8861\uff1a<\/strong>\u5982\u679c\u958b\u5f15\u865f\u548c\u9589\u5f15\u865f\u7684\u6578\u91cf\u4e0d\u5e73\u8861\uff0c\u5247\u6703\u51fa\u73fe\u6b64\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u67e5\u8a62 <code>SELECT * FROM table WHERE name = 'John;<\/code> \u82e5\u5728\u7d50\u5c3e\u591a\u4e86\u4e00\u500b\u55ae\u5f15\u865f\uff0c\u6703\u5c0e\u81f4\u932f\u8aa4\u3002<\/li>\n<li><strong>\u5f15\u865f\u8f49\u7fa9\uff1a<\/strong>\u5728 PostgreSQL \u4e2d\uff0c\u82e5\u60a8\u9700\u8981\u5728\u5b57\u4e32\u5e38\u91cf\u4e2d\u5305\u542b\u55ae\u5f15\u865f\uff0c\u5fc5\u9808\u4f7f\u7528\u5169\u500b\u9023\u7e8c\u7684\u55ae\u5f15\u865f (&#8221;) \u9032\u884c\u8f49\u7fa9\u3002\u5982\u679c\u672a\u6b63\u78ba\u8f49\u7fa9\u5f15\u865f\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-the-error-fAYDyCAaKj\">\u89e3\u6c7a\u932f\u8aa4\u7684\u65b9\u6cd5<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u64cd\u4f5c\uff1a<\/p>\n<h3 id=\"step-1-identify-the-query-fAYDyCAaKj\">\u6b65\u9a5f 1\uff1a\u8b58\u5225\u5c0e\u81f4\u932f\u8aa4\u7684\u67e5\u8a62<\/h3>\n<p>\u627e\u51fa\u89f8\u767c\u932f\u8aa4\u7684\u67e5\u8a62\u3002\u6aa2\u67e5\u60a8\u7684\u4ee3\u78bc\uff0c\u627e\u5230\u767c\u751f\u932f\u8aa4\u7684\u67e5\u8a62\uff0c\u7279\u5225\u6ce8\u610f\u67e5\u8a62\u4e2d\u7684\u5b57\u4e32\u5e38\u91cf\u3002<\/p>\n<h3 id=\"step-2-check-for-missing-or-unbalanced-quotes-fAYDyCAaKj\">\u6b65\u9a5f 2\uff1a\u6aa2\u67e5\u662f\u5426\u7f3a\u5c11\u6216\u4e0d\u5e73\u8861\u7684\u5f15\u865f<\/h3>\n<p>\u6aa2\u67e5\u67e5\u8a62\uff0c\u78ba\u4fdd\u6240\u6709\u5b57\u4e32\u5e38\u91cf\u90fd\u7528\u55ae\u5f15\u865f (&#8221;) \u62ec\u8d77\u4f86\u3002\u6aa2\u67e5\u662f\u5426\u6709\u7f3a\u5c11\u6216\u4e0d\u5e73\u8861\u7684\u5f15\u865f\u3002\u5982\u679c\u767c\u73fe\u554f\u984c\uff0c\u8acb\u6dfb\u52a0\u6216\u5e73\u8861\u5f15\u865f\u3002<\/p>\n<h3 id=\"step-3-escape-quotes-if-necessary-fAYDyCAaKj\">\u6b65\u9a5f 3\uff1a\u5982\u6709\u9700\u8981\uff0c\u8f49\u7fa9\u5f15\u865f<\/h3>\n<p>\u5982\u679c\u9700\u8981\u5728\u5b57\u4e32\u5e38\u91cf\u4e2d\u5305\u542b\u55ae\u5f15\u865f\uff0c\u8acb\u52d9\u5fc5\u4f7f\u7528\u5169\u500b\u9023\u7e8c\u7684\u55ae\u5f15\u865f (&#8221;) \u4f86\u6b63\u78ba\u8f49\u7fa9\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u5c07\u540d\u5b57 O&#8217;Brien \u63d2\u5165\u5230\u8868\u4e2d\uff0c\u67e5\u8a62\u61c9\u70ba <code>INSERT INTO table (name) VALUES ('O''Brien');<\/code>\u3002<\/p>\n<h3 id=\"step-4-test-the-query-fAYDyCAaKj\">\u6b65\u9a5f 4\uff1a\u6e2c\u8a66\u67e5\u8a62<\/h3>\n<p>\u5728\u9032\u884c\u5fc5\u8981\u7684\u66f4\u6539\u5f8c\uff0c\u6e2c\u8a66\u8a72\u67e5\u8a62\uff0c\u78ba\u4fdd PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string \u4e0d\u518d\u767c\u751f\u3002\u57f7\u884c\u67e5\u8a62\uff0c\u4e26\u78ba\u8a8d\u5176\u80fd\u5920\u6b63\u5e38\u904b\u884c\u4e14\u7121\u932f\u8aa4\u3002<\/p>\n<h2 id=\"summary-fAYDyCAaKj\">\u7e3d\u7d50<\/h2>\n<p>\u8981\u89e3\u6c7a PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a22024 &#8211; unterminated_c_string\uff0c\u60a8\u9700\u8981\u4ed4\u7d30\u6aa2\u67e5\u67e5\u8a62\uff0c\u78ba\u4fdd\u6240\u6709\u5b57\u4e32\u5e38\u91cf\u6b63\u78ba\u5730\u7528\u55ae\u5f15\u865f\u62ec\u8d77\u4f86\u3002\u6b64\u5916\uff0c\u8acb\u8a18\u5f97\u5728\u5fc5\u8981\u6642\u8f49\u7fa9\u5f15\u865f\u3002\u901a\u904e\u9075\u5faa\u9019\u4e9b\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u4e26\u78ba\u4fdd PostgreSQL \u6578\u64da\u5eab\u7684\u9806\u66a2\u904b\u884c\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u4e14\u9ad8\u6027\u80fd\u7684 VPS \u8a17\u7ba1\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u5148\u9032\u6280\u8853\u548c\u5353\u8d8a\u7684\u5ba2\u6236\u652f\u6301\uff0c\u63d0\u4f9b\u91dd\u5c0d\u60a8\u7279\u5b9a\u9700\u6c42\u7684\u9802\u7d1a VPS \u8a17\u7ba1\u670d\u52d9\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-21313","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21313","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=21313"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21313\/revisions"}],"predecessor-version":[{"id":24201,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21313\/revisions\/24201"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}