{"id":44254,"date":"2023-08-14T19:09:04","date_gmt":"2022-08-04T20:44:17","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/"},"modified":"2024-01-15T11:59:03","modified_gmt":"2024-01-15T03:59:03","slug":"%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/","title":{"rendered":"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d"},"content":{"rendered":"<h3>\u6211\u6682\u65f6\u63d2\u5165\u4e86\u4e00\u884c\u6587\u5b57\u8bd5\u8bd5\u770b\u3002<\/h3>\n<pre class=\"post-pre\"><code>package main                                                                                       \r\n\r\nimport (\r\n    \"database\/sql\"\r\n    \"fmt\"\r\n\r\n    _ \"github.com\/lib\/pq\"\r\n)\r\n\r\nconst (\r\n    host     = \"localhost\"\r\n    port     = 5432\r\n    user     = \"postgres\"\r\n    password = \"1234\"\r\n    dbname   = \"sample\"\r\n)\r\n\r\nfunc main() {\r\n    psqlInfo := fmt.Sprintf(\"host=%s user=%s password=%s dbname=%s sslmode=disable\", host,user,password,dbname)\r\n    fmt.Println(psqlInfo)\r\n    db, err := sql.Open(\"postgres\", psqlInfo)\r\n    if err != nil {\r\n        panic(err)\r\n    }   \r\n    defer db.Close()\r\n\r\n    sqlStatement := `\r\n    INSERT INTO account (id) values (30)`\r\n    _, err = db.Exec(sqlStatement)\r\n    if err != nil {\r\n        panic(err)\r\n    }   \r\n\r\n}\r\n\r\n<\/code><\/pre>\n<p>\u4f7f\u7528 db.Query \u8fdb\u884c\u591a\u884c\u7684 Select \u64cd\u4f5c\u3002<\/p>\n<p>\u53c2\u8003\uff1a\u4f7f\u7528Go\u7684sql\u5305\u67e5\u8be2\u591a\u4e2a\u8bb0\u5f55<br \/>\n[Go\u8bed\u8a00] \u5c1d\u8bd5\u4f7f\u7528database\/sql\u5305\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u6682\u65f6\u63d2\u5165\u4e86\u4e00\u884c\u6587\u5b57\u8bd5\u8bd5\u770b\u3002 package main import ( &#8220;database\/sql&#8221; &#8220;fm [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-44254","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\" \/>\n<meta property=\"og:description\" content=\"\u6211\u6682\u65f6\u63d2\u5165\u4e86\u4e00\u884c\u6587\u5b57\u8bd5\u8bd5\u770b\u3002 package main import ( &quot;database\/sql&quot; &quot;fm [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2022-08-04T20:44:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-15T03:59:03+00:00\" \/>\n<meta name=\"author\" content=\"\u97f5, \u79d1\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u97f5, \u79d1\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/\",\"name\":\"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2022-08-04T20:44:17+00:00\",\"dateModified\":\"2024-01-15T03:59:03+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e\",\"name\":\"\u97f5, \u79d1\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g\",\"caption\":\"\u97f5, \u79d1\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d","og_description":"\u6211\u6682\u65f6\u63d2\u5165\u4e86\u4e00\u884c\u6587\u5b57\u8bd5\u8bd5\u770b\u3002 package main import ( \"database\/sql\" \"fm [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2022-08-04T20:44:17+00:00","article_modified_time":"2024-01-15T03:59:03+00:00","author":"\u97f5, \u79d1","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u97f5, \u79d1"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/","name":"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2022-08-04T20:44:17+00:00","dateModified":"2024-01-15T03:59:03+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u4f7f\u7528golang\u5c06\u6570\u636e\u63d2\u5165\u5230postgres\u4e2d"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/6530331a63adef3b3443a1fab53a0e6e","name":"\u97f5, \u79d1","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/429ccb39b3fff5188bc17986222cfb0936cbadb8cc933cff04ab5ca01bd30a08?s=96&d=mm&r=g","caption":"\u97f5, \u79d1"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yunke\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e4%bd%bf%e7%94%a8golang%e5%b0%86%e6%95%b0%e6%8d%ae%e6%8f%92%e5%85%a5%e5%88%b0postgres%e4%b8%ad%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/44254","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=44254"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/44254\/revisions"}],"predecessor-version":[{"id":59268,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/44254\/revisions\/59268"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=44254"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=44254"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=44254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}