{"id":247316,"date":"2024-01-02T20:18:20","date_gmt":"2024-01-02T12:18:20","guid":{"rendered":"https:\/\/www.idc.net\/help\/247316\/"},"modified":"2024-01-02T20:18:20","modified_gmt":"2024-01-02T12:18:20","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%a4%8dpostgresql%e9%94%99%e8%af%af%e4%bb%a3%e7%a0%81%ef%bc%9ap0000-plpgsql_error%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/idc.net\/help\/247316\/","title":{"rendered":"\u5982\u4f55\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801\uff1aP0000 &#8211; plpgsql_error\uff1f"},"content":{"rendered":"<p><title id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%a4%8dpostgresql%e9%94%99%e8%af%af%e4%bb%a3%e7%a0%81%ef%bc%9ap0000-plpgsql_error%ef%bc%9f-citurYuNlb\">\u5982\u4f55\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801\uff1aP0000 - plpgsql_error\uff1f<\/title><\/p>\n<h1 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%a4%8dpostgresql%e9%94%99%e8%af%af%e4%bb%a3%e7%a0%81%ef%bc%9ap0000-plpgsql_error%ef%bc%9f-citurYuNlb\">\u5982\u4f55\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801\uff1aP0000 - plpgsql_error\uff1f<\/h1>\n<p>PostgreSQL\u662f\u4e00\u79cd\u529f\u80fd\u5f3a\u5927\u7684\u5f00\u6e90\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u89c4\u6a21\u7684\u4f01\u4e1a\u548c\u9879\u76ee\u4e2d\u3002\u7136\u800c\uff0c\u5c31\u50cf\u5176\u4ed6\u8f6f\u4ef6\u4e00\u6837\uff0cPostgreSQL\u4e5f\u53ef\u80fd\u4f1a\u51fa\u73b0\u9519\u8bef\u3002\u672c\u6587\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801\uff1aP0000 - plpgsql_error\u3002<\/p>\n<h2 id=\"%e9%94%99%e8%af%af%e4%bb%a3%e7%a0%81%ef%bc%9ap0000-plpgsql_error-citurYuNlb\">\u9519\u8bef\u4ee3\u7801\uff1aP0000 - plpgsql_error<\/h2>\n<p>\u5f53\u5728PostgreSQL\u4e2d\u4f7f\u7528PL\/pgSQL\u7f16\u7a0b\u8bed\u8a00\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u9519\u8bef\u4ee3\u7801P0000 - plpgsql_error\u3002\u8fd9\u4e2a\u9519\u8bef\u4ee3\u7801\u8868\u793a\u5728PL\/pgSQL\u51fd\u6570\u6216\u8fc7\u7a0b\u4e2d\u53d1\u751f\u4e86\u4e00\u4e2a\u9519\u8bef\u3002\u901a\u5e38\uff0c\u5f53\u51fd\u6570\u6216\u8fc7\u7a0b\u4e2d\u7684\u8bed\u53e5\u65e0\u6cd5\u6267\u884c\u6216\u6267\u884c\u51fa\u9519\u65f6\uff0c\u5c31\u4f1a\u89e6\u53d1\u8fd9\u4e2a\u9519\u8bef\u4ee3\u7801\u3002<\/p>\n<h2 id=\"%e4%bf%ae%e5%a4%8d%e6%96%b9%e6%b3%95-citurYuNlb\">\u4fee\u590d\u65b9\u6cd5<\/h2>\n<p>\u8981\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801P0000 - plpgsql_error\uff0c\u60a8\u53ef\u4ee5\u91c7\u53d6\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li>\u68c0\u67e5\u51fd\u6570\u6216\u8fc7\u7a0b\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\uff1a\u9996\u5148\uff0c\u60a8\u5e94\u8be5\u4ed4\u7ec6\u68c0\u67e5\u51fd\u6570\u6216\u8fc7\u7a0b\u4e2d\u7684\u8bed\u6cd5\u9519\u8bef\u3002\u786e\u4fdd\u6240\u6709\u7684\u8bed\u53e5\u90fd\u6309\u7167\u6b63\u786e\u7684\u8bed\u6cd5\u7f16\u5199\uff0c\u5e76\u4e14\u6ca1\u6709\u9057\u6f0f\u7684\u5206\u53f7\u6216\u62ec\u53f7\u3002<\/li>\n<li>\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\uff1aPostgreSQL\u4f1a\u5c06\u9519\u8bef\u4fe1\u606f\u8bb0\u5f55\u5728\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\u4e2d\u3002\u60a8\u53ef\u4ee5\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\uff0c\u4ee5\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u9519\u8bef\u7684\u8be6\u7ec6\u4fe1\u606f\u3002\u9519\u8bef\u65e5\u5fd7\u6587\u4ef6\u901a\u5e38\u4f4d\u4e8ePostgreSQL\u5b89\u88c5\u76ee\u5f55\u7684\"logs\"\u6587\u4ef6\u5939\u4e2d\u3002<\/li>\n<li>\u4f7f\u7528TRY...CATCH\u5757\uff1a\u5982\u679c\u60a8\u5728\u51fd\u6570\u6216\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u4e86PL\/pgSQL\u7684TRY...CATCH\u5757\uff0c\u60a8\u53ef\u4ee5\u5728CATCH\u5757\u4e2d\u6355\u83b7\u5e76\u5904\u7406\u9519\u8bef\u3002\u901a\u8fc7\u4f7f\u7528CATCH\u5757\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u63a7\u5236\u9519\u8bef\u5904\u7406\u6d41\u7a0b\uff0c\u5e76\u63d0\u4f9b\u66f4\u53cb\u597d\u7684\u9519\u8bef\u6d88\u606f\u3002<\/li>\n<li>\u8c03\u8bd5\u4ee3\u7801\uff1a\u5982\u679c\u4ee5\u4e0a\u65b9\u6cd5\u90fd\u65e0\u6cd5\u89e3\u51b3\u95ee\u9898\uff0c\u60a8\u53ef\u4ee5\u5c1d\u8bd5\u4f7f\u7528\u8c03\u8bd5\u5de5\u5177\u6765\u5206\u6790\u4ee3\u7801\u5e76\u627e\u51fa\u9519\u8bef\u6240\u5728\u3002PostgreSQL\u63d0\u4f9b\u4e86\u4e00\u4e9b\u8c03\u8bd5\u5de5\u5177\uff0c\u5982pgAdmin\u548cpgdbg\u3002<\/li>\n<\/ol>\n<h2 id=\"%e7%a4%ba%e4%be%8b%e4%bb%a3%e7%a0%81-citurYuNlb\">\u793a\u4f8b\u4ee3\u7801<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff0c\u6f14\u793a\u4e86\u5982\u4f55\u5728PL\/pgSQL\u51fd\u6570\u4e2d\u5904\u7406\u9519\u8bef\uff1a<\/p>\n<pre>\nCREATE OR REPLACE FUNCTION example_function() RETURNS VOID AS $$\nBEGIN\n    -- \u4e00\u4e9b\u4ee3\u7801...\n    -- \u53ef\u80fd\u4f1a\u89e6\u53d1\u9519\u8bef\u7684\u8bed\u53e5\n    -- \u5982\u679c\u53d1\u751f\u9519\u8bef\uff0c\u5c06\u4f1a\u8df3\u8f6c\u5230EXCEPTION\u5757\n    -- \u5e76\u6267\u884c\u76f8\u5e94\u7684\u9519\u8bef\u5904\u7406\u903b\u8f91\nEXCEPTION\n    WHEN OTHERS THEN\n        -- \u9519\u8bef\u5904\u7406\u903b\u8f91\n        RAISE NOTICE 'An error occurred: %', SQLERRM;\nEND;\n$$ LANGUAGE plpgsql;\n<\/pre>\n<h2 id=\"%e6%80%bb%e7%bb%93-citurYuNlb\">\u603b\u7ed3<\/h2>\n<p>\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801P0000 - plpgsql_error\u53ef\u80fd\u9700\u8981\u60a8\u4ed4\u7ec6\u68c0\u67e5\u8bed\u6cd5\u9519\u8bef\u3001\u67e5\u770b\u9519\u8bef\u65e5\u5fd7\u3001\u4f7f\u7528TRY...CATCH\u5757\u6216\u8c03\u8bd5\u4ee3\u7801\u3002\u901a\u8fc7\u91c7\u53d6\u9002\u5f53\u7684\u63aa\u65bd\uff0c\u60a8\u53ef\u4ee5\u66f4\u597d\u5730\u5904\u7406\u9519\u8bef\uff0c\u5e76\u786e\u4fddPostgreSQL\u6570\u636e\u5e93\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5bfb\u627e\u53ef\u9760\u7684\u9999\u6e2f\u670d\u52a1\u5668\u63d0\u4f9b\u5546\uff0c\u540e\u6d6a\u4e91\u662f\u60a8\u7684\u9996\u9009\u3002\u6211\u4eec\u63d0\u4f9b\u9ad8\u6027\u80fd\u7684\u9999\u6e2f\u670d\u52a1\u5668\uff0c\u53ef\u6ee1\u8db3\u60a8\u7684\u5404\u79cd\u9700\u6c42\u3002\u60a8\u53ef\u4ee5\u8bbf\u95ee\u6211\u4eec\u7684\u5b98\u7f51\u4e86\u89e3\u66f4\u591a\u4fe1\u606f\uff1a<a href=\"https:\/\/idc.net\">https:\/\/idc.net<\/a>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4fee\u590dPostgreSQL\u9519\u8bef\u4ee3\u7801\uff1aP0000 - plpgsql_error\uff1f \u5982\u4f55\u4fee\u590dPostgreSQ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7038],"tags":[],"class_list":["post-247316","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/247316","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/comments?post=247316"}],"version-history":[{"count":0,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/posts\/247316\/revisions"}],"wp:attachment":[{"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/media?parent=247316"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/categories?post=247316"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/idc.net\/help\/wp-json\/wp\/v2\/tags?post=247316"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}