{"id":178680,"date":"2024-11-08T19:59:22","date_gmt":"2024-11-08T11:59:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/178680\/"},"modified":"2024-11-08T19:59:23","modified_gmt":"2024-11-08T11:59:23","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%9a22003-numeric_value_out_of_range%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/178680\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a22003 &#8211; numeric_value_out_of_range\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%9a22003-numeric_value_out_of_range%ef%bc%9f-iWVEpetqkz\">\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a22003 &#8211; numeric_value_out_of_range\uff1f<\/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\u5c31\u662f\u932f\u8aa4\u4ee3\u78bc22003\uff0c\u8868\u793a\u300cnumeric_value_out_of_range\u300d\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u767c\u751f\u5728\u6578\u503c\u8d85\u51fa\u5176\u6578\u64da\u985e\u578b\u7684\u7bc4\u570d\u6642\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u9019\u500b\u932f\u8aa4\u7684\u539f\u56e0\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc22003%e7%9a%84%e5%8e%9f%e5%9b%a0-iWVEpetqkz\">\u932f\u8aa4\u4ee3\u78bc22003\u7684\u539f\u56e0<\/h2>\n<p>PostgreSQL\u4e2d\u7684\u6578\u503c\u985e\u578b\u5305\u62ec\u6574\u6578\uff08integer\uff09\u3001\u6d6e\u9ede\u6578\uff08float\uff09\u3001\u6578\u5b57\uff08numeric\uff09\u7b49\u3002\u6bcf\u7a2e\u6578\u64da\u985e\u578b\u90fd\u6709\u5176\u7279\u5b9a\u7684\u7bc4\u570d\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li><strong>\u6574\u6578\uff08integer\uff09<\/strong>\uff1a\u7bc4\u570d\u70ba-2,147,483,648\u52302,147,483,647\u3002<\/li>\n<li><strong>\u6d6e\u9ede\u6578\uff08float\uff09<\/strong>\uff1a\u7bc4\u570d\u53d6\u6c7a\u65bc\u7cbe\u5ea6\uff0c\u4f46\u901a\u5e38\u53ef\u4ee5\u8868\u793a\u975e\u5e38\u5927\u7684\u6578\u5b57\u3002<\/li>\n<li><strong>\u6578\u5b57\uff08numeric\uff09<\/strong>\uff1a\u53ef\u4ee5\u6307\u5b9a\u7cbe\u5ea6\u548c\u5c0f\u6578\u4f4d\u6578\uff0c\u4f46\u5982\u679c\u8d85\u51fa\u6307\u5b9a\u7684\u7bc4\u570d\uff0c\u5247\u6703\u5f15\u767c\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<p>\u7576\u4f60\u5617\u8a66\u63d2\u5165\u6216\u66f4\u65b0\u4e00\u500b\u8d85\u51fa\u9019\u4e9b\u7bc4\u570d\u7684\u6578\u503c\u6642\uff0c\u5c31\u6703\u51fa\u73fe22003\u932f\u8aa4\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0bSQL\u8a9e\u53e5\u5c07\u5c0e\u81f4\u932f\u8aa4\uff1a<\/p>\n<pre><code>INSERT INTO my_table (my_column) VALUES (3000000000);<\/code><\/pre>\n<p>\u5982\u679cmy_column\u7684\u6578\u64da\u985e\u578b\u662f\u6574\u6578\uff0c\u5247\u6703\u56e0\u70ba\u6578\u503c\u8d85\u51fa\u7bc4\u570d\u800c\u5f15\u767c\u932f\u8aa4\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a922003%e9%8c%af%e8%aa%a4-iWVEpetqkz\">\u5982\u4f55\u4fee\u5fa922003\u932f\u8aa4<\/h2>\n<p>\u4fee\u5fa9\u9019\u500b\u932f\u8aa4\u7684\u7b2c\u4e00\u6b65\u662f\u78ba\u5b9a\u5c0e\u81f4\u932f\u8aa4\u7684\u5177\u9ad4\u6578\u64da\u985e\u578b\u548c\u7bc4\u570d\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u89e3\u6c7a\u65b9\u6848\uff1a<\/p>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-iWVEpetqkz\">1. \u6aa2\u67e5\u6578\u64da\u985e\u578b<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u8868\u4e2d\u76f8\u61c9\u5217\u7684\u6578\u64da\u985e\u578b\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u67e5\u8a62\u4f86\u67e5\u770b\u8868\u7d50\u69cb\uff1a<\/p>\n<pre><code>SELECT column_name, data_type FROM information_schema.columns WHERE table_name = 'my_table';<\/code><\/pre>\n<p>\u78ba\u4fdd\u4f60\u63d2\u5165\u7684\u6578\u503c\u5728\u8a72\u6578\u64da\u985e\u578b\u7684\u7bc4\u570d\u5167\u3002\u5982\u679c\u4e0d\u5728\u7bc4\u570d\u5167\uff0c\u8003\u616e\u66f4\u6539\u6578\u64da\u985e\u578b\u3002<\/p>\n<h3 id=\"2-%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-iWVEpetqkz\">2. \u66f4\u6539\u6578\u64da\u985e\u578b<\/h3>\n<p>\u5982\u679c\u4f60\u9700\u8981\u5b58\u5132\u66f4\u5927\u7684\u6578\u503c\uff0c\u53ef\u4ee5\u8003\u616e\u5c07\u6578\u64da\u985e\u578b\u66f4\u6539\u70ba\u66f4\u5927\u7684\u985e\u578b\uff0c\u4f8b\u5982\u5f9e\u6574\u6578\u66f4\u6539\u70ba\u5927\u6574\u6578\uff08bigint\uff09\u6216\u6578\u5b57\uff08numeric\uff09\u3002\u4ee5\u4e0b\u662f\u66f4\u6539\u6578\u64da\u985e\u578b\u7684SQL\u8a9e\u53e5\uff1a<\/p>\n<pre><code>ALTER TABLE my_table ALTER COLUMN my_column TYPE bigint;<\/code><\/pre>\n<h3 id=\"3-%e6%95%b8%e6%93%9a%e9%a9%97%e8%ad%89-iWVEpetqkz\">3. \u6578\u64da\u9a57\u8b49<\/h3>\n<p>\u5728\u63d2\u5165\u6216\u66f4\u65b0\u6578\u64da\u4e4b\u524d\uff0c\u9032\u884c\u6578\u64da\u9a57\u8b49\u662f\u500b\u597d\u7fd2\u6163\u3002\u4f60\u53ef\u4ee5\u5728\u61c9\u7528\u7a0b\u5e8f\u5c64\u9762\u4e0a\u6aa2\u67e5\u6578\u503c\u662f\u5426\u5728\u5141\u8a31\u7684\u7bc4\u570d\u5167\uff0c\u9019\u6a23\u53ef\u4ee5\u907f\u514d\u4e0d\u5fc5\u8981\u7684\u932f\u8aa4\u3002<\/p>\n<h3 id=\"4-%e4%bd%bf%e7%94%a8%e4%be%8b%e5%a4%96%e8%99%95%e7%90%86-iWVEpetqkz\">4. \u4f7f\u7528\u4f8b\u5916\u8655\u7406<\/h3>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u4f7f\u7528\u4f8b\u5916\u8655\u7406\u4f86\u6355\u7372\u932f\u8aa4\u4e26\u9032\u884c\u76f8\u61c9\u7684\u8655\u7406\u4e5f\u662f\u4e00\u500b\u4e0d\u932f\u7684\u9078\u64c7\u3002\u9019\u6a23\u53ef\u4ee5\u5728\u932f\u8aa4\u767c\u751f\u6642\u63d0\u4f9b\u66f4\u53cb\u597d\u7684\u932f\u8aa4\u4fe1\u606f\uff0c\u800c\u4e0d\u662f\u8b93\u61c9\u7528\u7a0b\u5e8f\u5d29\u6f70\u3002<\/p>\n<pre><code>BEGIN;\n    INSERT INTO my_table (my_column) VALUES (3000000000);\nEXCEPTION\n    WHEN numeric_value_out_of_range THEN\n        RAISE NOTICE '\u6578\u503c\u8d85\u51fa\u7bc4\u570d\uff0c\u8acb\u6aa2\u67e5\u8f38\u5165\u3002';\nEND;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-iWVEpetqkz\">\u7e3d\u7d50<\/h2>\n<p>PostgreSQL\u932f\u8aa4\u4ee3\u78bc22003\u901a\u5e38\u662f\u7531\u65bc\u6578\u503c\u8d85\u51fa\u5176\u6578\u64da\u985e\u578b\u7684\u7bc4\u570d\u6240\u5f15\u8d77\u7684\u3002\u901a\u904e\u6aa2\u67e5\u6578\u64da\u985e\u578b\u3001\u9069\u7576\u5730\u66f4\u6539\u6578\u64da\u985e\u578b\u3001\u9032\u884c\u6578\u64da\u9a57\u8b49\u4ee5\u53ca\u4f7f\u7528\u4f8b\u5916\u8655\u7406\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u4fee\u5fa9\u9019\u500b\u932f\u8aa4\u3002\u4e86\u89e3\u9019\u4e9b\u57fa\u672c\u6982\u5ff5\u5c07\u6709\u52a9\u65bc\u958b\u767c\u8005\u5728\u4f7f\u7528PostgreSQL\u6642\u66f4\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK\u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u7528\u6236\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u9805\u76ee\u9084\u662f\u5927\u578b\u61c9\u7528\uff0c\u6211\u5011\u7684 <a href=\"https:\/\/server.hk\">\u4e91\u4f3a\u670d\u5668<\/a> \u90fd\u80fd\u70ba\u4f60\u63d0\u4f9b\u53ef\u9760\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc22003\uff1anumeric_value_out_of_range\uff0c\u89e3\u6c7a\u6578\u503c\u8d85\u51fa\u7bc4\u570d\u7684\u554f\u984c\uff0c\u78ba\u4fdd\u6578\u64da\u6b63\u78ba\u6027\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-178680","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178680","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=178680"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178680\/revisions"}],"predecessor-version":[{"id":178681,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178680\/revisions\/178681"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=178680"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=178680"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=178680"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}