{"id":6958,"date":"2024-11-14T12:54:07","date_gmt":"2024-11-14T04:54:07","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6958\/"},"modified":"2024-11-14T12:54:07","modified_gmt":"2024-11-14T04:54:07","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e5%bc%82%e6%9e%84%e6%95%b0%e6%8d%ae%e6%a0%bc%e5%bc%8f%e5%af%bc%e5%85%a5postgresql%e6%95%b0%e6%8d%ae%e5%ba%93%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6958\/","title":{"rendered":"\u5982\u4f55\u5c06\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165PostgreSQL\u6570\u636e\u5e93\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173018239645633.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165PostgreSQL\u6570\u636e\u5e93\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165PostgreSQL\u6570\u636e\u5e93\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165 postgresql \u6570\u636e\u5e93<\/strong><\/p>\n<p>\u4f5c\u4e3a\u4e00\u540d\u65b0\u624b\uff0c\u60a8\u5e0c\u671b\u5c06\u590d\u6742\u7684\u6570\u636e\u683c\u5f0f\u5bfc\u5165\u6570\u636e\u5e93\uff0c\u4f8b\u5982 postgresql\u3002\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u4e24\u4e2a\u89d2\u5ea6\u6765\u89e3\u51b3\uff1a \u548c postgresql\u3002<\/p>\n<p><strong>mysql<\/strong><\/p>\n<p><strong>1. \u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\uff1a<\/strong><\/p>\n<pre>create database my_database;\ncreate table my_table (\n  code char(50),\n  topic char(50),\n  author char(50)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u4f7f\u7528 load data infile \u547d\u4ee4\u5bfc\u5165\u6570\u636e\uff1a<\/strong><\/p>\n<pre>load data infile 'data.txt'\ninto table my_table\nfields terminated by '\t';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>postgresql<\/strong><\/p>\n<p>\u8f6c\u6362\u4e3a postgresql \u7684  \u7248\u9a71\u52a8\u7a0b\u5e8f\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6279\u91cf\u5bfc\u5165\uff1a<\/p>\n<p><strong>1. \u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\uff1a<\/strong><\/p>\n<pre>import psycopg2\n\n# \u8fde\u63a5 postresql \u6570\u636e\u5e93\nconn = psycopg2.connect(\n    host=\"localhost\",\n    port=5432,\n    database=\"my_database\",\n    user=\"my_user\",\n    password=\"my_password\"\n)\ncur = conn.cursor()\n\n# \u521b\u5efa\u8868\ncur.execute(\"create table info (code char(50), topic char(50), author char(50))\")<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5bfc\u5165\u6570\u636e\uff1a<\/strong><\/p>\n<pre># \u521b\u5efa\u4e00\u4e2a\u51c6\u5907\u597d\u7684\u8bed\u53e5\u5bf9\u8c61\nstmt = conn.cursor(\"insert into info values (%s, %s, %s)\")\n\n# \u4f7f\u7528\u53ef\u8fed\u4ee3\u5bf9\u8c61\u6279\u91cf\u63d2\u5165\u6570\u636e\nrows = [\n    [\"007\", \"the paron lal\", \"pardon110|candy\"],\n    [\"008\", \"the paron lal 2\", \"pardon110|candy 2\"]\n]\n\nstmt.executemany(\"insert into info values (%s, %s, %s)\", rows)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u63d0\u4ea4\u66f4\u6539\uff1a<\/strong><\/p>\n<pre>conn.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\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165PostgreSQL\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>\u5982\u4f55\u5c06\u5f02\u6784\u6570\u636e\u683c\u5f0f\u5bfc\u5165 postgresql \u6570\u636e\u5e93 \u4f5c\u4e3a\u4e00\u540d\u65b0\u624b\uff0c\u60a8\u5e0c\u671b\u5c06\u590d\u6742\u7684\u6570\u636e\u683c\u5f0f\u5bfc\u5165\u6570\u636e\u5e93\uff0c\u4f8b\u5982 postgresql\u3002\u8fd9\u4e2a\u95ee\u9898\u53ef\u4ee5\u4ece\u4ee5\u4e0b\u4e24\u4e2a\u89d2\u5ea6\u6765\u89e3\u51b3\uff1a \u548c postgresql\u3002 mysql 1. \u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\uff1a create database my_database; create table my_table ( code char(50), topic char(50), author char(50) ); \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528 load data infile \u547d\u4ee4\u5bfc\u5165\u6570\u636e\uff1a load data infile &#8216;data.txt&#8217; into table my_table fields terminated by &#8216; &#8216;; \u767b\u5f55\u540e\u590d\u5236 postgresql \u8f6c\u6362\u4e3a postgresql \u7684 \u7248\u9a71\u52a8\u7a0b\u5e8f\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u6279\u91cf\u5bfc\u5165\uff1a 1. \u521b\u5efa\u6570\u636e\u5e93\u548c\u8868\uff1a import psycopg2 # \u8fde\u63a5 [&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-6958","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6958","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=6958"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6958\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}