{"id":179128,"date":"2024-11-08T23:14:19","date_gmt":"2024-11-08T15:14:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/179128\/"},"modified":"2024-11-08T23:14:20","modified_gmt":"2024-11-08T15:14:20","slug":"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9-postgresql-%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc%ef%bc%9ahv004-fdw_invalid_data_type%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/179128\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1aHV004 &#8211; fdw_invalid_data_type\uff1f"},"content":{"rendered":"<h1 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9-postgresql-%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc%ef%bc%9ahv004-fdw_invalid_data_type-CJquQegIZq\">\u5982\u4f55\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc\uff1aHV004 &#8211; fdw_invalid_data_type<\/h1>\n<p>\u5728\u4f7f\u7528 PostgreSQL \u6578\u64da\u5eab\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u9047\u5230\u5404\u7a2e\u932f\u8aa4\u4ee3\u78bc\uff0c\u5176\u4e2d\u4e4b\u4e00\u662f HV004 &#8211; fdw_invalid_data_type\u3002\u9019\u500b\u932f\u8aa4\u901a\u5e38\u8207\u5916\u90e8\u6578\u64da\u5305\uff08Foreign Data Wrapper, FDW\uff09\u6709\u95dc\uff0c\u7279\u5225\u662f\u5728\u5617\u8a66\u5f9e\u5916\u90e8\u6578\u64da\u6e90\u8b80\u53d6\u6578\u64da\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%bc-hv004-%e7%9a%84%e8%83%8c%e6%99%af-CJquQegIZq\">\u932f\u8aa4\u4ee3\u78bc HV004 \u7684\u80cc\u666f<\/h2>\n<p>HV004 \u932f\u8aa4\u4ee3\u78bc\u8868\u793a\u5728\u4f7f\u7528\u5916\u90e8\u6578\u64da\u5305\u6642\uff0c\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\u3002\u9019\u901a\u5e38\u767c\u751f\u5728\u4ee5\u4e0b\u60c5\u6cc1\uff1a<\/p>\n<ul>\n<li>\u7576\u4f60\u5617\u8a66\u5f9e\u5916\u90e8\u6578\u64da\u6e90\uff08\u5982\u5176\u4ed6\u6578\u64da\u5eab\u6216 API\uff09\u8b80\u53d6\u6578\u64da\u6642\uff0cPostgreSQL \u9700\u8981\u78ba\u5b9a\u6578\u64da\u985e\u578b\u662f\u5426\u8207\u672c\u5730\u8868\u7684\u6578\u64da\u985e\u578b\u76f8\u7b26\u3002<\/li>\n<li>\u5982\u679c\u5916\u90e8\u6578\u64da\u6e90\u7684\u6578\u64da\u985e\u578b\u8207 PostgreSQL \u4e2d\u5b9a\u7fa9\u7684\u6578\u64da\u985e\u578b\u4e0d\u517c\u5bb9\uff0c\u5247\u6703\u5f15\u767c HV004 \u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e5%8e%9f%e5%9b%a0-CJquQegIZq\">\u5e38\u898b\u539f\u56e0<\/h2>\n<p>HV004 \u932f\u8aa4\u7684\u5e38\u898b\u539f\u56e0\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\uff1a<\/strong>\u5916\u90e8\u6578\u64da\u6e90\u7684\u6578\u64da\u985e\u578b\u8207 PostgreSQL \u4e2d\u7684\u6578\u64da\u985e\u578b\u4e0d\u4e00\u81f4\u3002\u4f8b\u5982\uff0c\u5916\u90e8\u6578\u64da\u6e90\u4e2d\u7684\u6574\u6578\u985e\u578b\u53ef\u80fd\u5728 PostgreSQL \u4e2d\u88ab\u5b9a\u7fa9\u70ba\u6d6e\u9ede\u6578\u3002<\/li>\n<li><strong>FDW \u914d\u7f6e\u932f\u8aa4\uff1a<\/strong>\u5728\u8a2d\u7f6e\u5916\u90e8\u6578\u64da\u5305\u6642\uff0c\u53ef\u80fd\u672a\u6b63\u78ba\u914d\u7f6e\u6578\u64da\u985e\u578b\u6620\u5c04\u3002<\/li>\n<li><strong>\u7248\u672c\u4e0d\u517c\u5bb9\uff1a<\/strong>\u4f7f\u7528\u7684 PostgreSQL \u7248\u672c\u8207\u5916\u90e8\u6578\u64da\u6e90\u7684\u7248\u672c\u4e0d\u517c\u5bb9\uff0c\u53ef\u80fd\u5c0e\u81f4\u6578\u64da\u985e\u578b\u7684\u89e3\u91cb\u4e0d\u540c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e8%a7%a3%e6%b1%ba%e6%96%b9%e6%a1%88-CJquQegIZq\">\u89e3\u6c7a\u65b9\u6848<\/h2>\n<p>\u8981\u4fee\u5fa9 HV004 \u932f\u8aa4\uff0c\u53ef\u4ee5\u63a1\u53d6\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e6%95%b8%e6%93%9a%e9%a1%9e%e5%9e%8b-CJquQegIZq\">1. \u6aa2\u67e5\u6578\u64da\u985e\u578b<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u5916\u90e8\u6578\u64da\u6e90\u7684\u6578\u64da\u985e\u578b\u8207 PostgreSQL \u4e2d\u7684\u6578\u64da\u985e\u578b\u662f\u5426\u5339\u914d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u67e5\u8a62\u4f86\u6aa2\u67e5 PostgreSQL \u8868\u7684\u7d50\u69cb\uff1a<\/p>\n<pre><code>SELECT column_name, data_type \nFROM information_schema.columns \nWHERE table_name = 'your_table_name';<\/code><\/pre>\n<p>\u78ba\u4fdd\u5916\u90e8\u6578\u64da\u6e90\u7684\u6578\u64da\u985e\u578b\u8207\u67e5\u8a62\u7d50\u679c\u4e2d\u7684\u6578\u64da\u985e\u578b\u4e00\u81f4\u3002<\/p>\n<h3 id=\"2-%e6%9b%b4%e6%96%b0-fdw-%e9%85%8d%e7%bd%ae-CJquQegIZq\">2. \u66f4\u65b0 FDW \u914d\u7f6e<\/h3>\n<p>\u5982\u679c\u767c\u73fe\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\uff0c\u5247\u9700\u8981\u66f4\u65b0 FDW \u7684\u914d\u7f6e\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b SQL \u8a9e\u53e5\u4f86\u4fee\u6539\u5916\u90e8\u8868\u7684\u6578\u64da\u985e\u578b\uff1a<\/p>\n<pre><code>CREATE FOREIGN TABLE your_foreign_table (\n    column_name data_type\n) SERVER your_server\nOPTIONS (table 'external_table_name');<\/code><\/pre>\n<p>\u5728\u9019\u88e1\uff0c\u78ba\u4fdd\u5c07 <code>data_type<\/code> \u66ff\u63db\u70ba\u6b63\u78ba\u7684\u6578\u64da\u985e\u578b\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-cast-%e5%87%bd%e6%95%b8-CJquQegIZq\">3. \u4f7f\u7528 CAST \u51fd\u6578<\/h3>\n<p>\u5982\u679c\u7121\u6cd5\u66f4\u6539\u5916\u90e8\u6578\u64da\u6e90\u7684\u6578\u64da\u985e\u578b\uff0c\u53ef\u4ee5\u8003\u616e\u4f7f\u7528 CAST \u51fd\u6578\u4f86\u5f37\u5236\u8f49\u63db\u6578\u64da\u985e\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>SELECT CAST(column_name AS desired_data_type) \nFROM your_foreign_table;<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u5728\u67e5\u8a62\u6642\u5c07\u6578\u64da\u985e\u578b\u8f49\u63db\u70ba\u6240\u9700\u7684\u985e\u578b\u3002<\/p>\n<h3 id=\"4-%e6%aa%a2%e6%9f%a5%e7%89%88%e6%9c%ac%e5%85%bc%e5%ae%b9%e6%80%a7-CJquQegIZq\">4. \u6aa2\u67e5\u7248\u672c\u517c\u5bb9\u6027<\/h3>\n<p>\u6700\u5f8c\uff0c\u6aa2\u67e5 PostgreSQL \u548c\u5916\u90e8\u6578\u64da\u6e90\u7684\u7248\u672c\u662f\u5426\u517c\u5bb9\u3002\u5982\u679c\u767c\u73fe\u4e0d\u517c\u5bb9\uff0c\u8003\u616e\u5347\u7d1a\u6216\u964d\u7d1a PostgreSQL \u6216\u5916\u90e8\u6578\u64da\u6e90\u7684\u7248\u672c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-CJquQegIZq\">\u7e3d\u7d50<\/h2>\n<p>HV004 &#8211; fdw_invalid_data_type \u932f\u8aa4\u901a\u5e38\u662f\u7531\u65bc\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\u5f15\u8d77\u7684\u3002\u901a\u904e\u6aa2\u67e5\u6578\u64da\u985e\u578b\u3001\u66f4\u65b0 FDW \u914d\u7f6e\u3001\u4f7f\u7528 CAST \u51fd\u6578\u4ee5\u53ca\u6aa2\u67e5\u7248\u672c\u517c\u5bb9\u6027\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u6c7a\u6b64\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u7684\u6578\u64da\u5eab\u89e3\u6c7a\u65b9\u6848\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u670d\u52d9\u53ef\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4fee\u5fa9 PostgreSQL \u932f\u8aa4\u4ee3\u78bc HV004 &#8211; fdw_invalid_data_type \u7684\u65b9\u6cd5\uff0c\u5e6b\u52a9\u60a8\u89e3\u6c7a\u5916\u90e8\u6578\u64da\u5305\u88dd\u5668\u7684\u6578\u64da\u985e\u578b\u554f\u984c\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-179128","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179128","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=179128"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179128\/revisions"}],"predecessor-version":[{"id":179129,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/179128\/revisions\/179129"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=179128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=179128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=179128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}