{"id":6961,"date":"2024-11-14T13:32:15","date_gmt":"2024-11-14T05:32:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6961\/"},"modified":"2024-11-14T13:32:15","modified_gmt":"2024-11-14T05:32:15","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b0%e6%8d%ae%e9%ab%98%e6%95%88%e5%af%bc%e5%85%a5-postgresql-%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6961\/","title":{"rendered":"\u5982\u4f55\u5c06\u6570\u636e\u9ad8\u6548\u5bfc\u5165 PostgreSQL \u6570\u636e\u5e93\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173018648978733.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u6570\u636e\u9ad8\u6548\u5bfc\u5165 PostgreSQL \u6570\u636e\u5e93\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u6570\u636e\u9ad8\u6548\u5bfc\u5165 PostgreSQL \u6570\u636e\u5e93\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5c06\u6570\u636e\u5b58\u50a8\u5230 postgresql \u6570\u636e\u5e93\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\uff0c\u5c06\u590d\u6742\u683c\u5f0f\u7684\u6570\u636e\u5bfc\u5165\u6570\u636e\u5e93\u53ef\u80fd\u4f1a\u8ba9\u4eba\u671b\u800c\u751f\u754f\uff0c\u4f46\u638c\u63e1\u6b63\u786e\u7684\u6280\u672f\u53ef\u4ee5\u7b80\u5316\u8fd9\u4e00\u8fc7\u7a0b\u3002\u672c\u6587\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u5c06\u7c7b\u4f3c\u4e8e\u63d0\u4f9b\u7684\u793a\u4f8b\u6570\u636e\u5bfc\u5165 postgresql \u6570\u636e\u5e93\u3002<\/p>\n<p><strong>\u4f7f\u7528 <\/strong><\/p>\n<p>\u4e3a\u4e86\u5728 mysql \u4e2d\u5bfc\u5165\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 load data infile \u8bed\u53e5\u3002\u8be5\u8bed\u53e5\u5141\u8bb8\u60a8\u4ece\u6587\u672c\u6587\u4ef6\u76f4\u63a5\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u8868\u4e2d\u3002\u8be6\u7ec6\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>load data infile 'file_name.txt' into table table_name\n(column_name1, column_name2, ...)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f7f\u7528 postgresql<\/strong><\/p>\n<p>postgresql \u63d0\u4f9b\u4e86 copy \u547d\u4ee4\uff0c\u5b83\u4e0e mysql \u7684 load data infile \u7c7b\u4f3c\u3002\u8be5\u547d\u4ee4\u5141\u8bb8\u60a8\u5c06\u6570\u636e\u4ece\u6587\u4ef6\u6216\u6807\u51c6\u8f93\u5165\u4e2d\u590d\u5236\u5230\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>copy table_name (column_name1, column_name2, ...)\nfrom 'file_name.txt'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528  \u7684 psycopg2 \u5e93\u6765\u4e0e postgresql \u6570\u636e\u5e93\u4ea4\u4e92\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 psycopg2 \u5c06\u6570\u636e\u63d2\u5165\u5230 info \u8868\u4e2d\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>import psycopg2\n\n# \u5efa\u7acb\u8fde\u63a5\nconn = psycopg2.connect(\n    \"host=localhost\",\n    \"dbname=database_name\",\n    \"user=username\",\n    \"password=password\"\n)\n\n# \u521b\u5efa\u6e38\u6807\ncur = conn.cursor()\n\n# INSERT \u8bed\u53e5\nstmt = cur.prepare(\"INSERT INTO info (code, topic, author) VALUES ($1, $2, $3)\")\n\n# \u6267\u884c\u8bed\u53e5\nstmt(\n    \"007\",\n    \"The Paron lal\",\n    \"pardon110|Candy\"\n)\n\n# \u63d0\u4ea4\u66f4\u6539\nconn.commit()\n\n# \u5173\u95ed\u8fde\u63a5\ncur.close()\nconn.close()<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06\u6570\u636e\u9ad8\u6548\u5bfc\u5165 PostgreSQL \u6570\u636e\u5e93\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c06\u6570\u636e\u5b58\u50a8\u5230 postgresql \u6570\u636e\u5e93\u7684\u65b9\u6cd5 \u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\uff0c\u5c06\u590d\u6742\u683c\u5f0f\u7684\u6570\u636e\u5bfc\u5165\u6570\u636e\u5e93\u53ef\u80fd\u4f1a\u8ba9\u4eba\u671b\u800c\u751f\u754f\uff0c\u4f46\u638c\u63e1\u6b63\u786e\u7684\u6280\u672f\u53ef\u4ee5\u7b80\u5316\u8fd9\u4e00\u8fc7\u7a0b\u3002\u672c\u6587\u5c06\u91cd\u70b9\u4ecb\u7ecd\u5982\u4f55\u5c06\u7c7b\u4f3c\u4e8e\u63d0\u4f9b\u7684\u793a\u4f8b\u6570\u636e\u5bfc\u5165 postgresql \u6570\u636e\u5e93\u3002 \u4f7f\u7528 \u4e3a\u4e86\u5728 mysql \u4e2d\u5bfc\u5165\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 load data infile \u8bed\u53e5\u3002\u8be5\u8bed\u53e5\u5141\u8bb8\u60a8\u4ece\u6587\u672c\u6587\u4ef6\u76f4\u63a5\u5c06\u6570\u636e\u52a0\u8f7d\u5230\u8868\u4e2d\u3002\u8be6\u7ec6\u8bed\u6cd5\u5982\u4e0b\uff1a load data infile &#8216;file_name.txt&#8217; into table table_name (column_name1, column_name2, &#8230;) \u767b\u5f55\u540e\u590d\u5236 \u4f7f\u7528 postgresql postgresql \u63d0\u4f9b\u4e86 copy \u547d\u4ee4\uff0c\u5b83\u4e0e mysql \u7684 load data infile \u7c7b\u4f3c\u3002\u8be5\u547d\u4ee4\u5141\u8bb8\u60a8\u5c06\u6570\u636e\u4ece\u6587\u4ef6\u6216\u6807\u51c6\u8f93\u5165\u4e2d\u590d\u5236\u5230\u8868\u4e2d\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a copy table_name (column_name1, column_name2, &#8230;) from &#8216;file_name.txt&#8217; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u5916\uff0c\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528 \u7684 psycopg2 \u5e93\u6765\u4e0e postgresql \u6570\u636e\u5e93\u4ea4\u4e92\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528 psycopg2 \u5c06\u6570\u636e\u63d2\u5165\u5230 info \u8868\u4e2d\u7684\u793a\u4f8b\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6961","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6961","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6961"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6961\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}