{"id":96832,"date":"2024-10-20T12:44:15","date_gmt":"2024-10-20T04:44:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/96832\/"},"modified":"2024-10-20T12:44:16","modified_gmt":"2024-10-20T04:44:16","slug":"postgresql-42809-%e9%8c%af%e8%aa%a4%e7%9a%84%e5%b0%8d%e8%b1%a1%e9%a1%9e%e5%9e%8b-%e6%8a%a5%e9%94%99-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%a4%8d-%e8%bf%9c%e7%a8%8b%e5%a4%84%e7%90%86","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/96832\/","title":{"rendered":"PostgreSQL 42809: \u932f\u8aa4\u7684\u5c0d\u8c61\u985e\u578b \u62a5\u9519 \u6545\u969c\u4fee\u590d \u8fdc\u7a0b\u5904\u7406"},"content":{"rendered":"<h1 id=\"postgresql-42809-%e9%8c%af%e8%aa%a4%e7%9a%84%e5%b0%8d%e8%b1%a1%e9%a1%9e%e5%9e%8b-%e6%8a%a5%e9%94%99-%e6%95%85%e9%9a%9c%e4%bf%ae%e5%a4%8d-%e8%bf%9c%e7%a8%8b%e5%a4%84%e7%90%86-cZEARkcVOM\">PostgreSQL 42809: \u932f\u8aa4\u7684\u5c0d\u8c61\u985e\u578b \u62a5\u9519 \u6545\u969c\u4fee\u590d \u8fdc\u7a0b\u5904\u7406<\/h1>\n<p>\u5728\u4f7f\u7528 PostgreSQL \u6570\u636e\u5e93\u65f6\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u9047\u5230\u5404\u5f0f\u5404\u6837\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u5176\u4e2d\u4e4b\u4e00\u4fbf\u662f\u201c<code>42809<\/code>: \u932f\u8aa4\u7684\u5c0d\u8c61\u985e\u578b\u201d\u3002\u8fd9\u4e2a\u9519\u8bef\u901a\u5e38\u51fa\u73b0\u5728\u5c1d\u8bd5\u6267\u884c\u67d0\u4e9b\u64cd\u4f5c\u65f6\uff0c\u6240\u6d89\u53ca\u7684\u5bf9\u8c61\u7c7b\u578b\u4e0e\u9884\u671f\u4e0d\u7b26\u3002\u672c\u6587\u5c06\u6df1\u5165\u63a2\u8ba8\u8be5\u9519\u8bef\u7684\u6210\u56e0\u3001\u89e3\u51b3\u65b9\u6848\u4ee5\u53ca\u5982\u4f55\u8fdb\u884c\u8fdc\u7a0b\u5904\u7406\u3002<\/p>\n<h2 id=\"%e9%94%99%e8%af%af%e5%8e%9f%e5%9b%a0%e5%88%86%e6%9e%90-cZEARkcVOM\">\u9519\u8bef\u539f\u56e0\u5206\u6790<\/h2>\n<p>PostgreSQL \u7684\u9519\u8bef\u4ee3\u7801 <code>42809<\/code> \u901a\u5e38\u8868\u793a\u5728\u6267\u884c\u67d0\u4e2a SQL \u8bed\u53e5\u65f6\uff0c\u6240\u5f15\u7528\u7684\u5bf9\u8c61\u7c7b\u578b\u4e0d\u7b26\u5408\u8981\u6c42\u3002\u8fd9\u79cd\u60c5\u51b5\u53ef\u80fd\u53d1\u751f\u5728\u4ee5\u4e0b\u51e0\u79cd\u573a\u666f\u4e2d\uff1a<\/p>\n<ul>\n<li><strong>\u51fd\u6570\u8c03\u7528\u9519\u8bef\uff1a<\/strong>\u5f53\u8c03\u7528\u4e00\u4e2a\u51fd\u6570\u65f6\uff0c\u4f20\u5165\u7684\u53c2\u6570\u7c7b\u578b\u4e0e\u51fd\u6570\u5b9a\u4e49\u4e0d\u5339\u914d\u3002<\/li>\n<li><strong>\u89e6\u53d1\u5668\u6216\u89c4\u5219\u9519\u8bef\uff1a<\/strong>\u5728\u5b9a\u4e49\u89e6\u53d1\u5668\u6216\u89c4\u5219\u65f6\uff0c\u6240\u5f15\u7528\u7684\u8868\u6216\u5217\u7c7b\u578b\u4e0d\u6b63\u786e\u3002<\/li>\n<li><strong>\u89c6\u56fe\u6216\u7d22\u5f15\u9519\u8bef\uff1a<\/strong>\u5728\u521b\u5efa\u89c6\u56fe\u6216\u7d22\u5f15\u65f6\uff0c\u6240\u4f7f\u7528\u7684\u5217\u7c7b\u578b\u4e0d\u7b26\u5408\u9884\u671f\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570\uff0c\u671f\u671b\u63a5\u6536\u4e00\u4e2a\u6574\u6570\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u4f46\u5728\u8c03\u7528\u65f6\u5374\u4f20\u5165\u4e86\u4e00\u4e2a\u5b57\u7b26\u4e32\u7c7b\u578b\u7684\u53c2\u6570\uff0c\u5c31\u4f1a\u5bfc\u81f4\u6b64\u9519\u8bef\u3002<\/p>\n<h2 id=\"%e6%95%85%e9%9a%9c%e4%bf%ae%e5%a4%8d%e6%ad%a5%e9%aa%a4-cZEARkcVOM\">\u6545\u969c\u4fee\u590d\u6b65\u9aa4<\/h2>\n<p>\u8981\u4fee\u590d <code>42809<\/code> \u9519\u8bef\uff0c\u9996\u5148\u9700\u8981\u786e\u8ba4\u9519\u8bef\u7684\u5177\u4f53\u6765\u6e90\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u89c1\u7684\u6545\u969c\u6392\u9664\u6b65\u9aa4\uff1a<\/p>\n<h3 id=\"1-%e6%a3%80%e6%9f%a5%e5%87%bd%e6%95%b0%e5%8f%82%e6%95%b0%e7%b1%bb%e5%9e%8b-cZEARkcVOM\">1. \u68c0\u67e5\u51fd\u6570\u53c2\u6570\u7c7b\u578b<\/h3>\n<pre><code>CREATE OR REPLACE FUNCTION example_function(integer) RETURNS void AS $$\nBEGIN\n    -- \u51fd\u6570\u4f53\nEND;\n$$ LANGUAGE plpgsql;\n\n-- \u8c03\u7528\u51fd\u6570\u65f6\u786e\u4fdd\u53c2\u6570\u7c7b\u578b\u6b63\u786e\nSELECT example_function(123);  -- \u6b63\u786e\nSELECT example_function('abc');  -- \u9519\u8bef\n<\/code><\/pre>\n<h3 id=\"2-%e9%aa%8c%e8%af%81%e8%a7%a6%e5%8f%91%e5%99%a8%e5%92%8c%e8%a7%84%e5%88%99-cZEARkcVOM\">2. \u9a8c\u8bc1\u89e6\u53d1\u5668\u548c\u89c4\u5219<\/h3>\n<p>\u786e\u4fdd\u89e6\u53d1\u5668\u6216\u89c4\u5219\u4e2d\u5f15\u7528\u7684\u8868\u548c\u5217\u7c7b\u578b\u4e0e\u5b9e\u9645\u5b9a\u4e49\u4e00\u81f4\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>CREATE TRIGGER example_trigger\nAFTER INSERT ON example_table\nFOR EACH ROW EXECUTE FUNCTION example_function();\n<\/code><\/pre>\n<h3 id=\"3-%e6%a3%80%e6%9f%a5%e8%a7%86%e5%9b%be%e5%92%8c%e7%b4%a2%e5%bc%95%e5%ae%9a%e4%b9%89-cZEARkcVOM\">3. \u68c0\u67e5\u89c6\u56fe\u548c\u7d22\u5f15\u5b9a\u4e49<\/h3>\n<p>\u5728\u521b\u5efa\u89c6\u56fe\u6216\u7d22\u5f15\u65f6\uff0c\u786e\u4fdd\u6240\u4f7f\u7528\u7684\u5217\u7c7b\u578b\u4e0e\u539f\u8868\u4e00\u81f4\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8be2\u6765\u68c0\u67e5\u8868\u7ed3\u6784\uff1a<\/p>\n<pre><code>SELECT column_name, data_type\nFROM information_schema.columns\nWHERE table_name = 'example_table';\n<\/code><\/pre>\n<h2 id=\"%e8%bf%9c%e7%a8%8b%e5%a4%84%e7%90%86%e5%bb%ba%e8%ae%ae-cZEARkcVOM\">\u8fdc\u7a0b\u5904\u7406\u5efa\u8bae<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5f00\u53d1\u8005\u53ef\u80fd\u9700\u8981\u8fdc\u7a0b\u5904\u7406 PostgreSQL \u6570\u636e\u5e93\u4e2d\u7684\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8bae\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528 SSH \u8fde\u63a5\uff1a<\/strong>\u901a\u8fc7 SSH \u8fde\u63a5\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\uff0c\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u8fdb\u884c\u6545\u969c\u6392\u9664\u3002<\/li>\n<li><strong>\u4f7f\u7528 pgAdmin\uff1a<\/strong>\u5229\u7528 pgAdmin \u7b49\u56fe\u5f62\u5316\u5de5\u5177\uff0c\u65b9\u4fbf\u5730\u67e5\u770b\u6570\u636e\u5e93\u5bf9\u8c61\u53ca\u5176\u5c5e\u6027\u3002<\/li>\n<li><strong>\u65e5\u5fd7\u5206\u6790\uff1a<\/strong>\u67e5\u770b PostgreSQL \u7684\u65e5\u5fd7\u6587\u4ef6\uff0c\u83b7\u53d6\u66f4\u591a\u5173\u4e8e\u9519\u8bef\u7684\u4fe1\u606f\u3002<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u66f4\u6709\u6548\u5730\u5b9a\u4f4d\u548c\u89e3\u51b3 <code>42809<\/code> \u9519\u8bef\uff0c\u786e\u4fdd\u6570\u636e\u5e93\u7684\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<h2 id=\"%e6%80%bb%e7%bb%93-cZEARkcVOM\">\u603b\u7ed3<\/h2>\n<p>PostgreSQL \u7684 <code>42809<\/code> \u9519\u8bef\u901a\u5e38\u4e0e\u5bf9\u8c61\u7c7b\u578b\u4e0d\u5339\u914d\u6709\u5173\uff0c\u89e3\u51b3\u6b64\u95ee\u9898\u9700\u8981\u4ed4\u7ec6\u68c0\u67e5\u51fd\u6570\u3001\u89e6\u53d1\u5668\u3001\u89c6\u56fe\u548c\u7d22\u5f15\u7684\u5b9a\u4e49\u3002\u901a\u8fc7\u9002\u5f53\u7684\u6545\u969c\u6392\u9664\u6b65\u9aa4\u548c\u8fdc\u7a0b\u5904\u7406\u65b9\u6cd5\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6709\u6548\u5730\u4fee\u590d\u6b64\u9519\u8bef\uff0c\u786e\u4fdd\u6570\u636e\u5e93\u7684\u7a33\u5b9a\u6027\u548c\u53ef\u9760\u6027\u3002\u5bf9\u4e8e\u9700\u8981\u9ad8\u6548\u6570\u636e\u5e93\u7ba1\u7406\u7684\u7528\u6237\uff0c\u9009\u62e9\u5408\u9002\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u51b3\u65b9\u6848\u5c06\u662f\u4e00\u4e2a\u660e\u667a\u7684\u9009\u62e9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u89e3\u51b3PostgreSQL 42809\u9519\u8bef\uff1a\u9519\u8bef\u7684\u5bf9\u8c61\u7c7b\u578b\u3002\u4e86\u89e3\u6545\u969c\u4fee\u590d\u548c\u8fdc\u7a0b\u5904\u7406\u65b9\u6cd5\uff0c\u786e\u4fdd\u6570\u636e\u5e93\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-96832","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96832","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=96832"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96832\/revisions"}],"predecessor-version":[{"id":96833,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/96832\/revisions\/96833"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=96832"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=96832"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=96832"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}