{"id":178798,"date":"2024-11-08T20:59:19","date_gmt":"2024-11-08T12:59:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/178798\/"},"modified":"2024-11-08T20:59:19","modified_gmt":"2024-11-08T12:59:19","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9postgresql%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc%ef%bc%9a22p01-floating_point_exception%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/178798\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a22P01 &#8211; floating_point_exception\uff1f"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9postgresql%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc%ef%bc%9a22p01-floating_point_exception-duyYmldwAk\">\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a22P01 &#8211; floating_point_exception<\/h1>\n<p>\u5728\u4f7f\u7528PostgreSQL\u6578\u64da\u5eab\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\u4ee3\u78bc\uff0c\u5176\u4e2d\u4e4b\u4e00\u662f22P01\uff0c\u9019\u662f\u4e00\u500b\u8207\u6d6e\u9ede\u6578\u904b\u7b97\u76f8\u95dc\u7684\u7570\u5e38\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u500b\u932f\u8aa4\u7684\u6210\u56e0\u3001\u5f71\u97ff\u4ee5\u53ca\u5982\u4f55\u6709\u6548\u5730\u4fee\u5fa9\u5b83\u3002<\/p>\n<h2 id=\"%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc22p01%e7%9a%84%e5%90%ab%e7%be%a9-duyYmldwAk\">\u932f\u8aa4\u4ee3\u78bc22P01\u7684\u542b\u7fa9<\/h2>\n<p>PostgreSQL\u7684\u932f\u8aa4\u4ee3\u78bc22P01\u8868\u793a\u300c\u6d6e\u9ede\u6578\u7570\u5e38\u300d\uff08floating_point_exception\uff09\u3002\u9019\u901a\u5e38\u767c\u751f\u5728\u9032\u884c\u6578\u5b78\u904b\u7b97\u6642\uff0c\u5c24\u5176\u662f\u6d89\u53ca\u6d6e\u9ede\u6578\u7684\u8a08\u7b97\u3002\u7576\u6578\u64da\u5eab\u5617\u8a66\u57f7\u884c\u4e00\u500b\u4e0d\u5408\u6cd5\u7684\u6d6e\u9ede\u904b\u7b97\u6642\uff0c\u4f8b\u5982\u9664\u4ee5\u96f6\u6216\u8a08\u7b97\u8d85\u51fa\u6d6e\u9ede\u6578\u7bc4\u570d\u7684\u503c\uff0c\u5c31\u6703\u5f15\u767c\u6b64\u932f\u8aa4\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84%e8%a7%b8%e7%99%bc%e6%83%85%e6%b3%81-duyYmldwAk\">\u5e38\u898b\u7684\u89f8\u767c\u60c5\u6cc1<\/h2>\n<ul>\n<li><strong>\u9664\u4ee5\u96f6\uff1a<\/strong>\u7576\u4e00\u500b\u6d6e\u9ede\u6578\u88ab\u96f6\u9664\u6642\uff0c\u6703\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u7121\u6548\u7684\u6578\u5b78\u904b\u7b97\uff1a<\/strong>\u4f8b\u5982\uff0c\u8a08\u7b97\u5e73\u65b9\u6839\u6642\u50b3\u5165\u8ca0\u6578\u3002<\/li>\n<li><strong>\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\uff1a<\/strong>\u5728\u9032\u884c\u8a08\u7b97\u6642\uff0c\u82e5\u6578\u64da\u985e\u578b\u4e0d\u6b63\u78ba\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e8%a8%ba%e6%96%b7%e5%95%8f%e9%a1%8c-duyYmldwAk\">\u5982\u4f55\u8a3a\u65b7\u554f\u984c<\/h2>\n<p>\u8981\u4fee\u5fa922P01\u932f\u8aa4\uff0c\u9996\u5148\u9700\u8981\u8a3a\u65b7\u554f\u984c\u7684\u6839\u6e90\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6b65\u9a5f\u4f86\u5e6b\u52a9\u60a8\u627e\u51fa\u554f\u984c\u6240\u5728\uff1a<\/p>\n<ol>\n<li><strong>\u6aa2\u67e5SQL\u67e5\u8a62\uff1a<\/strong>\u4ed4\u7d30\u6aa2\u67e5\u5f15\u767c\u932f\u8aa4\u7684SQL\u67e5\u8a62\uff0c\u7279\u5225\u662f\u6d89\u53ca\u6d6e\u9ede\u6578\u7684\u90e8\u5206\u3002<\/li>\n<li><strong>\u67e5\u770b\u6578\u64da\u985e\u578b\uff1a<\/strong>\u78ba\u4fdd\u6240\u6709\u53c3\u8207\u8a08\u7b97\u7684\u5b57\u6bb5\u90fd\u5177\u6709\u6b63\u78ba\u7684\u6578\u64da\u985e\u578b\u3002<\/li>\n<li><strong>\u4f7f\u7528\u65e5\u8a8c\uff1a<\/strong>\u555f\u7528PostgreSQL\u7684\u65e5\u8a8c\u529f\u80fd\uff0c\u4ee5\u4fbf\u7372\u53d6\u66f4\u591a\u932f\u8aa4\u4fe1\u606f\u3002<\/li>\n<\/ol>\n<h2 id=\"%e4%bf%ae%e5%be%a9%e6%96%b9%e6%b3%95-duyYmldwAk\">\u4fee\u5fa9\u65b9\u6cd5<\/h2>\n<p>\u4e00\u65e6\u78ba\u5b9a\u4e86\u554f\u984c\u7684\u6839\u6e90\uff0c\u60a8\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u63aa\u65bd\u4f86\u4fee\u5fa9\u932f\u8aa4\uff1a<\/p>\n<h3 id=\"1-%e8%99%95%e7%90%86%e9%99%a4%e4%bb%a5%e9%9b%b6%e7%9a%84%e6%83%85%e6%b3%81-duyYmldwAk\">1. \u8655\u7406\u9664\u4ee5\u96f6\u7684\u60c5\u6cc1<\/h3>\n<pre><code>SELECT CASE \n    WHEN denominator = 0 THEN NULL \n    ELSE numerator \/ denominator \nEND AS result\nFROM your_table;<\/code><\/pre>\n<p>\u5728\u9019\u500b\u4f8b\u5b50\u4e2d\uff0c\u6211\u5011\u4f7f\u7528\u4e86CASE\u8a9e\u53e5\u4f86\u907f\u514d\u9664\u4ee5\u96f6\u7684\u60c5\u6cc1\uff0c\u5f9e\u800c\u9632\u6b62\u932f\u8aa4\u7684\u767c\u751f\u3002<\/p>\n<h3 id=\"2-%e6%aa%a2%e6%9f%a5%e6%95%b8%e6%93%9a%e6%9c%89%e6%95%88%e6%80%a7-duyYmldwAk\">2. \u6aa2\u67e5\u6578\u64da\u6709\u6548\u6027<\/h3>\n<p>\u5728\u9032\u884c\u8a08\u7b97\u4e4b\u524d\uff0c\u78ba\u4fdd\u6240\u6709\u6578\u64da\u90fd\u662f\u6709\u6548\u7684\u3002\u4f8b\u5982\uff0c\u5c0d\u65bc\u5e73\u65b9\u6839\u8a08\u7b97\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\uff1a<\/p>\n<pre><code>SELECT CASE \n    WHEN value &lt; 0 THEN NULL \n    ELSE SQRT(value) \nEND AS result\nFROM your_table;<\/code><\/pre>\n<h3 id=\"3-%e7%a2%ba%e4%bf%9d%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b%e6%ad%a3%e7%a2%ba-duyYmldwAk\">3. \u78ba\u4fdd\u6578\u64da\u985e\u578b\u6b63\u78ba<\/h3>\n<p>\u5728\u9032\u884c\u8a08\u7b97\u6642\uff0c\u78ba\u4fdd\u6240\u6709\u53c3\u8207\u904b\u7b97\u7684\u5b57\u6bb5\u90fd\u70ba\u6d6e\u9ede\u6578\u985e\u578b\u3002\u5982\u679c\u9700\u8981\uff0c\u53ef\u4ee5\u4f7f\u7528CAST\u51fd\u6578\u4f86\u8f49\u63db\u6578\u64da\u985e\u578b\uff1a<\/p>\n<pre><code>SELECT CAST(numerator AS FLOAT) \/ CAST(denominator AS FLOAT) AS result\nFROM your_table;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-duyYmldwAk\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL\u932f\u8aa4\u4ee3\u78bc22P01 &#8211; floating_point_exception\u901a\u5e38\u662f\u7531\u65bc\u4e0d\u5408\u6cd5\u7684\u6d6e\u9ede\u6578\u904b\u7b97\u5f15\u8d77\u7684\u3002\u901a\u904e\u4ed4\u7d30\u6aa2\u67e5SQL\u67e5\u8a62\u3001\u6578\u64da\u985e\u578b\u548c\u6578\u64da\u6709\u6548\u6027\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u8a3a\u65b7\u548c\u4fee\u5fa9\u6b64\u932f\u8aa4\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u8655\u7406\u7684\u61c9\u7528\uff0c\u9078\u64c7\u5408\u9069\u7684<a href=\"https:\/\/server.hk\">VPS<\/a>\u89e3\u6c7a\u65b9\u6848\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u548c<a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a>\u7684\u8cc7\u8a0a\uff0c\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u60a8\u7684\u6578\u64da\u5eab\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc22P01 &#8211; floating_point_exception\uff0c\u89e3\u6c7a\u6d6e\u9ede\u904b\u7b97\u7570\u5e38\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u6b63\u5e38\u904b\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-178798","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178798","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=178798"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178798\/revisions"}],"predecessor-version":[{"id":178799,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178798\/revisions\/178799"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=178798"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=178798"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=178798"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}