{"id":178784,"date":"2024-11-08T20:52:19","date_gmt":"2024-11-08T12:52:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/178784\/"},"modified":"2024-11-08T20:52:20","modified_gmt":"2024-11-08T12:52:20","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%9a2203a-sql_json_member_not_found%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/178784\/","title":{"rendered":"\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a2203A &#8211; sql_json_member_not_found\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%9a2203a-sql_json_member_not_found-LQmbyWmXTG\">\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc\uff1a2203A &#8211; sql_json_member_not_found<\/h1>\n<p>\u5728\u4f7f\u7528PostgreSQL\u9032\u884c\u6578\u64da\u5eab\u7ba1\u7406\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\u78bc2203A\uff0c\u8a72\u932f\u8aa4\u901a\u5e38\u8868\u793a\u5728\u8655\u7406JSON\u6578\u64da\u6642\uff0c\u6307\u5b9a\u7684\u6210\u54e1\u672a\u627e\u5230\u3002\u9019\u7bc7\u6587\u7ae0\u5c07\u6df1\u5165\u63a2\u8a0e\u8a72\u932f\u8aa4\u7684\u539f\u56e0\u53ca\u5176\u89e3\u6c7a\u65b9\u6848\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u66f4\u6709\u6548\u5730\u8655\u7406\u6b64\u985e\u554f\u984c\u3002<\/p>\n<h2 id=\"%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc2203a%e7%9a%84%e8%83%8c%e6%99%af-LQmbyWmXTG\">\u932f\u8aa4\u4ee3\u78bc2203A\u7684\u80cc\u666f<\/h2>\n<p>PostgreSQL\u662f\u4e00\u500b\u5f37\u5927\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7cfb\u7d71\uff0c\u652f\u6301\u591a\u7a2e\u6578\u64da\u985e\u578b\uff0c\u5305\u62ecJSON\u548cJSONB\u3002\u9019\u4f7f\u5f97\u958b\u767c\u8005\u80fd\u5920\u9748\u6d3b\u5730\u5b58\u5132\u548c\u67e5\u8a62\u7d50\u69cb\u5316\u6578\u64da\u3002\u7136\u800c\uff0c\u7576\u67e5\u8a62JSON\u6578\u64da\u6642\uff0c\u5982\u679c\u6307\u5b9a\u7684\u9375\u6216\u6210\u54e1\u4e0d\u5b58\u5728\uff0c\u5247\u6703\u5f15\u767c\u932f\u8aa4\u4ee3\u78bc2203A\u3002<\/p>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e5%8e%9f%e5%9b%a0-LQmbyWmXTG\">\u5e38\u898b\u539f\u56e0<\/h2>\n<ul>\n<li><strong>\u9375\u540d\u62fc\u5beb\u932f\u8aa4\uff1a<\/strong>\u5728\u67e5\u8a62JSON\u6578\u64da\u6642\uff0c\u958b\u767c\u8005\u53ef\u80fd\u6703\u56e0\u70ba\u9375\u540d\u62fc\u5beb\u932f\u8aa4\u800c\u5c0e\u81f4\u627e\u4e0d\u5230\u8a72\u6210\u54e1\u3002<\/li>\n<li><strong>\u6578\u64da\u7d50\u69cb\u8b8a\u66f4\uff1a<\/strong>\u5982\u679c\u6578\u64da\u5eab\u4e2d\u7684JSON\u7d50\u69cb\u767c\u751f\u8b8a\u66f4\uff0c\u800c\u67e5\u8a62\u4ecd\u7136\u4f7f\u7528\u820a\u7684\u7d50\u69cb\uff0c\u5247\u6703\u51fa\u73fe\u6b64\u932f\u8aa4\u3002<\/li>\n<li><strong>\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\uff1a<\/strong>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u67e5\u8a62\u7684\u6578\u64da\u985e\u578b\u8207JSON\u6210\u54e1\u7684\u985e\u578b\u4e0d\u5339\u914d\uff0c\u4e5f\u53ef\u80fd\u5c0e\u81f4\u6b64\u932f\u8aa4\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e4%bf%ae%e5%be%a9%e9%8c%af%e8%aa%a4%e4%bb%a3%e7%a2%bc2203a-LQmbyWmXTG\">\u5982\u4f55\u4fee\u5fa9\u932f\u8aa4\u4ee3\u78bc2203A<\/h2>\n<h3 id=\"1-%e6%aa%a2%e6%9f%a5%e9%8d%b5%e5%90%8d-LQmbyWmXTG\">1. \u6aa2\u67e5\u9375\u540d<\/h3>\n<p>\u9996\u5148\uff0c\u6aa2\u67e5\u67e5\u8a62\u4e2d\u4f7f\u7528\u7684\u9375\u540d\u662f\u5426\u6b63\u78ba\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u67e5\u8a62\u4f86\u6aa2\u67e5JSON\u6578\u64da\u7684\u7d50\u69cb\uff1a<\/p>\n<pre><code>SELECT jsonb_object_keys(your_json_column) FROM your_table;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56deJSON\u5c0d\u8c61\u4e2d\u7684\u6240\u6709\u9375\uff0c\u5e6b\u52a9\u4f60\u78ba\u8a8d\u6240\u9700\u7684\u9375\u662f\u5426\u5b58\u5728\u3002<\/p>\n<h3 id=\"2-%e6%9b%b4%e6%96%b0%e6%9f%a5%e8%a9%a2%e4%bb%a5%e5%8c%b9%e9%85%8d%e6%95%b8%e6%93%9a%e7%b5%90%e6%a7%8b-LQmbyWmXTG\">2. \u66f4\u65b0\u67e5\u8a62\u4ee5\u5339\u914d\u6578\u64da\u7d50\u69cb<\/h3>\n<p>\u5982\u679c\u767c\u73fe\u6578\u64da\u7d50\u69cb\u5df2\u7d93\u8b8a\u66f4\uff0c\u5247\u9700\u8981\u66f4\u65b0\u67e5\u8a62\u4ee5\u5339\u914d\u65b0\u7684\u7d50\u69cb\u3002\u4f8b\u5982\uff0c\u5982\u679c\u539f\u672c\u7684\u67e5\u8a62\u662f\uff1a<\/p>\n<pre><code>SELECT your_json_column-&gt;&gt;'missing_key' FROM your_table;<\/code><\/pre>\n<p>\u800c\u5be6\u969b\u4e0a\u8a72\u9375\u5df2\u88ab\u66f4\u6539\u70ba\u201cnew_key\u201d\uff0c\u5247\u61c9\u5c07\u67e5\u8a62\u66f4\u65b0\u70ba\uff1a<\/p>\n<pre><code>SELECT your_json_column-&gt;&gt;'new_key' FROM your_table;<\/code><\/pre>\n<\/p>\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-LQmbyWmXTG\">3. \u78ba\u4fdd\u6578\u64da\u985e\u578b\u6b63\u78ba<\/h3>\n<p>\u5728\u67e5\u8a62JSON\u6578\u64da\u6642\uff0c\u78ba\u4fdd\u4f7f\u7528\u6b63\u78ba\u7684\u6578\u64da\u985e\u578b\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u671f\u671b\u4e00\u500b\u6574\u6578\u503c\uff0c\u4f46\u5be6\u969b\u4e0a\u8a72\u503c\u662f\u5b57\u7b26\u4e32\uff0c\u5247\u9700\u8981\u9032\u884c\u985e\u578b\u8f49\u63db\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u8a9e\u53e5\u9032\u884c\u985e\u578b\u8f49\u63db\uff1a<\/p>\n<pre><code>SELECT (your_json_column-&gt;&gt;'key')::integer FROM your_table;<\/code><\/pre>\n<h2 id=\"%e7%a4%ba%e4%be%8b-LQmbyWmXTG\">\u793a\u4f8b<\/h2>\n<p>\u5047\u8a2d\u6709\u4e00\u500b\u8868\u683c\u540d\u70ba\u201cusers\u201d\uff0c\u5176\u4e2d\u6709\u4e00\u500bJSONB\u5217\u201cprofile\u201d\uff0c\u5176\u7d50\u69cb\u5982\u4e0b\uff1a<\/p>\n<pre><code>{\n    \"name\": \"John Doe\",\n    \"age\": 30,\n    \"address\": {\n        \"city\": \"Hong Kong\",\n        \"zip\": \"10000\"\n    }\n}<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u5617\u8a66\u67e5\u8a62\u201caddress\u201d\u4e2d\u7684\u201ccountry\u201d\u9375\uff0c\u5247\u6703\u51fa\u73fe\u932f\u8aa42203A\uff0c\u56e0\u70ba\u8a72\u9375\u4e0d\u5b58\u5728\u3002\u6b63\u78ba\u7684\u67e5\u8a62\u61c9\u8a72\u662f\uff1a<\/p>\n<pre><code>SELECT profile-&gt;'address'-&gt;&gt;'city' FROM users;<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-LQmbyWmXTG\">\u7e3d\u7d50<\/h2>\n<p>\u932f\u8aa4\u4ee3\u78bc2203A\u901a\u5e38\u662f\u7531\u65bcJSON\u6578\u64da\u4e2d\u7684\u9375\u540d\u932f\u8aa4\u3001\u6578\u64da\u7d50\u69cb\u8b8a\u66f4\u6216\u6578\u64da\u985e\u578b\u4e0d\u5339\u914d\u6240\u5f15\u8d77\u7684\u3002\u901a\u904e\u4ed4\u7d30\u6aa2\u67e5\u67e5\u8a62\u548c\u6578\u64da\u7d50\u69cb\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u4fee\u5fa9\u6b64\u932f\u8aa4\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> \u6216 <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u662f\u81f3\u95dc\u91cd\u8981\u7684\uff0c\u9019\u6a23\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u4fee\u5fa9PostgreSQL\u932f\u8aa4\u4ee3\u78bc2203A\uff1asql_json_member_not_found\uff0c\u89e3\u6c7aJSON\u67e5\u8a62\u4e2d\u7684\u6210\u54e1\u672a\u627e\u5230\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-178784","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178784","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=178784"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178784\/revisions"}],"predecessor-version":[{"id":178785,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/178784\/revisions\/178785"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=178784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=178784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=178784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}