{"id":21405,"date":"2024-01-02T08:50:29","date_gmt":"2024-01-02T08:50:29","guid":{"rendered":"https:\/\/server.hk\/blog\/21405\/"},"modified":"2024-11-14T10:35:03","modified_gmt":"2024-11-14T02:35:03","slug":"how-to-fix-postgresql-error-code-42939-reserved_name","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/21405\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name"},"content":{"rendered":"<h1 id=\"how-to-fix-postgresql-error-code-42939-reserved_name-nSiQWuGlMB\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name<\/h1>\n<p>PostgreSQL \u662f\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u95dc\u806f\u5f0f\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5168\u7403\u958b\u767c\u8005\u548c\u7d44\u7e54\u5ee3\u6cdb\u4f7f\u7528\u3002\u7136\u800c\uff0c\u50cf\u4efb\u4f55\u8edf\u4ef6\u4e00\u6a23\uff0cPostgreSQL \u53ef\u80fd\u6703\u9047\u5230\u59a8\u7919\u5176\u529f\u80fd\u7684\u932f\u8aa4\u3002\u5176\u4e2d\u4e00\u500b\u932f\u8aa4\u662f PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6b64\u932f\u8aa4\u7684\u539f\u56e0\u4e26\u63d0\u4f9b\u9010\u6b65\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"understanding-postgresql-error-code-42939-reserved_name-nSiQWuGlMB\">\u7406\u89e3 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name<\/h2>\n<p>PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name \u767c\u751f\u5728\u4f60\u5617\u8a66\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c SQL \u67e5\u8a62\u4e2d\u7684\u6a19\u8b58\u7b26\u6642\u3002\u4fdd\u7559\u5b57\u662f PostgreSQL \u4e2d\u7684\u9810\u5b9a\u7fa9\u95dc\u9375\u5b57\uff0c\u5177\u6709\u7279\u5b9a\u7684\u542b\u7fa9\u548c\u529f\u80fd\u3002\u9019\u4e9b\u5b57\u5728\u672a\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u6642\u4e0d\u80fd\u4f5c\u70ba\u6a19\u8b58\u7b26\uff08\u5982\u8868\u540d\u6216\u5217\u540d\uff09\u4f7f\u7528\u3002<\/p>\n<p>\u7576\u4f60\u9047\u5230\u6b64\u932f\u8aa4\u6642\uff0cPostgreSQL \u5c07\u986f\u793a\u985e\u4f3c\u4ee5\u4e0b\u7684\u932f\u8aa4\u6d88\u606f\uff1a<\/p>\n<p><code>ERROR:  syntax error at or near \"reserved_word\"<br \/>\nLINE 1: SELECT * FROM reserved_word;<\/code><\/p>\n<p>\u932f\u8aa4\u6d88\u606f\u8868\u660e\uff0c\u4f60\u7528\u4f5c\u6a19\u8b58\u7b26\u7684\u4fdd\u7559\u5b57\u5728 SQL \u67e5\u8a62\u4e2d\u5f15\u8d77\u4e86\u8a9e\u6cd5\u932f\u8aa4\u3002<\/p>\n<h2 id=\"common-causes-of-postgresql-error-code-42939-reserved_name-nSiQWuGlMB\">PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name \u7684\u5e38\u898b\u539f\u56e0<\/h2>\n<p>\u9047\u5230 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name \u7684\u5e38\u898b\u539f\u56e0\u6709\u5e7e\u500b\uff1a<\/p>\n<ul>\n<li><strong>\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\uff1a<\/strong>\u5982\u524d\u6240\u8ff0\uff0c\u672a\u5c07\u4fdd\u7559\u5b57\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u4f86\u800c\u7528\u4f5c\u6a19\u8b58\u7b26\u6703\u5f15\u767c\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u62fc\u5beb\u932f\u8aa4\u7684\u4fdd\u7559\u5b57\uff1a<\/strong>\u5982\u679c\u62fc\u5beb\u932f\u8aa4\uff0cPostgreSQL \u4e0d\u6703\u8b58\u5225\u70ba\u4fdd\u7559\u5b57\uff0c\u800c\u6703\u5c07\u5176\u8996\u70ba\u666e\u901a\u6a19\u8b58\u7b26\u3002<\/li>\n<li><strong>\u5728\u7cfb\u7d71\u76ee\u9304\u4e2d\u4f7f\u7528\u4fdd\u7559\u5b57\uff1a<\/strong>PostgreSQL \u7cfb\u7d71\u76ee\u9304\uff0c\u5982 information_schema \u67b6\u69cb\u4e2d\u7684\u8868\u540d\uff0c\u53ef\u80fd\u5305\u542b\u4fdd\u7559\u5b57\u3002\u5617\u8a66\u5c07\u9019\u4e9b\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\u6703\u5c0e\u81f4\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"fixing-postgresql-error-code-42939-reserved_name-nSiQWuGlMB\">\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name<\/h2>\n<p>\u8981\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name\uff0c\u8acb\u6309\u7167\u4ee5\u4e0b\u6b65\u9a5f\u9032\u884c\uff1a<\/p>\n<h3 id=\"1-identify-the-reserved-word-nSiQWuGlMB\">1. \u8b58\u5225\u4fdd\u7559\u5b57<\/h3>\n<p>\u6aa2\u67e5\u4f60\u7684 SQL \u67e5\u8a62\uff0c\u8b58\u5225\u5f15\u8d77\u932f\u8aa4\u7684\u4fdd\u7559\u5b57\u3002\u5e38\u898b\u7684\u4fdd\u7559\u5b57\u5305\u62ec &#8220;SELECT&#8221;\u3001&#8221;FROM&#8221;\u3001&#8221;WHERE&#8221; \u548c &#8220;ORDER BY&#8221;\u3002\u78ba\u4fdd\u6c92\u6709\u5c07\u9019\u4e9b\u8a5e\u7528\u4f5c\u6a19\u8b58\u7b26\uff0c\u4e14\u672a\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u3002<\/p>\n<h3 id=\"2-enclose-the-reserved-word-in-double-quotes-nSiQWuGlMB\">2. \u7528\u96d9\u5f15\u865f\u62ec\u8d77\u4fdd\u7559\u5b57<\/h3>\n<p>\u5982\u679c\u9700\u8981\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\uff0c\u8acb\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u60f3\u5c07 &#8220;SELECT&#8221; \u7528\u4f5c\u8868\u540d\uff0c\u8acb\u5c07\u67e5\u8a62\u4fee\u6539\u5982\u4e0b\uff1a<\/p>\n<p><code>SELECT * FROM \"SELECT\";<\/code><\/p>\n<p>\u901a\u904e\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u4fdd\u7559\u5b57\uff0cPostgreSQL \u5c07\u5176\u8996\u70ba\u6a19\u8b58\u7b26\uff0c\u800c\u975e\u4fdd\u7559\u5b57\u3002<\/p>\n<h3 id=\"3-avoid-using-reserved-words-nSiQWuGlMB\">3. \u907f\u514d\u4f7f\u7528\u4fdd\u7559\u5b57<\/h3>\n<p>\u4e00\u822c\u5efa\u8b70\u5118\u53ef\u80fd\u907f\u514d\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\u3002\u4f7f\u7528\u63cf\u8ff0\u6027\u548c\u6709\u610f\u7fa9\u7684\u540d\u7a31\u70ba\u8868\u3001\u5217\u548c\u5176\u4ed6\u6578\u64da\u5eab\u5c0d\u8c61\u547d\u540d\uff0c\u53ef\u4ee5\u5e6b\u52a9\u9632\u6b62\u8207\u4fdd\u7559\u5b57\u7684\u885d\u7a81\u3002<\/p>\n<h3 id=\"4-check-for-misspelled-reserved-words-nSiQWuGlMB\">4. \u6aa2\u67e5\u62fc\u5beb\u932f\u8aa4\u7684\u4fdd\u7559\u5b57<\/h3>\n<p>\u5982\u679c\u4f60\u78ba\u4fe1\u6c92\u6709\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\uff0c\u8acb\u4ed4\u7d30\u6aa2\u67e5 SQL \u67e5\u8a62\u4e2d\u7684\u62fc\u5beb\u932f\u8aa4\u3002\u5373\u4f7f\u662f\u5c0f\u7684\u62fc\u5beb\u932f\u8aa4\u4e5f\u53ef\u80fd\u5c0e\u81f4 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name\u3002<\/p>\n<h3 id=\"5-use-aliases-nSiQWuGlMB\">5. \u4f7f\u7528\u5225\u540d<\/h3>\n<p>\u5982\u679c\u9700\u8981\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\uff0c\u800c\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u4e26\u4e0d\u7406\u60f3\uff0c\u5247\u53ef\u4ee5\u4f7f\u7528\u5225\u540d\u3002\u5225\u540d\u5141\u8a31\u4f60\u70ba\u6a19\u8b58\u7b26\u5206\u914d\u66ff\u4ee3\u540d\u7a31\u3002\u4f8b\u5982\uff1a<\/p>\n<p><code>SELECT column_name AS \"SELECT\" FROM table_name;<\/code><\/p>\n<p>\u901a\u904e\u4f7f\u7528\u5225\u540d\uff0c\u4f60\u53ef\u4ee5\u907f\u514d\u76f4\u63a5\u5c07\u4fdd\u7559\u5b57\u7528\u4f5c\u6a19\u8b58\u7b26\u3002<\/p>\n<h2 id=\"summary-nSiQWuGlMB\">\u7e3d\u7d50<\/h2>\n<p>\u7e3d\u4e4b\uff0cPostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1a42939 &#8211; reserved_name \u767c\u751f\u5728\u4f60\u672a\u5c07\u4fdd\u7559\u5b57\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u4f86\u800c\u7528\u4f5c\u6a19\u8b58\u7b26\u7684\u60c5\u6cc1\u4e0b\u3002\u8981\u4fee\u5fa9\u6b64\u932f\u8aa4\uff0c\u8b58\u5225\u5f15\u8d77\u554f\u984c\u7684\u4fdd\u7559\u5b57\uff0c\u4e26\u5c07\u5176\u7528\u96d9\u5f15\u865f\u62ec\u8d77\u3001\u907f\u514d\u4f7f\u7528\u4fdd\u7559\u5b57\u3001\u6aa2\u67e5\u62fc\u5beb\u932f\u8aa4\u7684\u4fdd\u7559\u5b57\uff0c\u6216\u4f7f\u7528\u5225\u540d\u3002\u8a18\u5f97\u59cb\u7d42\u70ba\u4f60\u7684\u6578\u64da\u5eab\u5c0d\u8c61\u4f7f\u7528\u63cf\u8ff0\u6027\u548c\u6709\u610f\u7fa9\u7684\u540d\u7a31\uff0c\u4ee5\u6700\u5c0f\u5316\u8207\u4fdd\u7559\u5b57\u7684\u885d\u7a81\u3002<\/p>\n<p>\u5982\u679c\u4f60\u9700\u8981\u53ef\u9760\u4e14\u9ad8\u6548\u7684 VPS \u8a17\u7ba1\u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8003\u616e <a href=\"https:\/\/server.hk\">Server.HK<\/a>\u3002\u6211\u5011\u7684\u9999\u6e2f VPS \u8a17\u7ba1\u670d\u52d9\u70ba\u904b\u884c PostgreSQL \u548c\u5176\u4ed6\u61c9\u7528\u7a0b\u5e8f\u63d0\u4f9b\u5b8c\u7f8e\u7684\u74b0\u5883\uff0c\u78ba\u4fdd\u9ad8\u6548\u548c\u5b89\u5168\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-21405","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21405","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=21405"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21405\/revisions"}],"predecessor-version":[{"id":24088,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/21405\/revisions\/24088"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=21405"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=21405"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=21405"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}