doubijiao2094 2017-03-23 22:50
浏览 287
已采纳

使用Golang对Redshift数据库进行CRUD操作

Could you please give me some explanations and some code examples on how it would be done (ex: creating tables and inserting data) ? Which library would you advise me to use ?

Thanks !

  • 写回答

1条回答 默认 最新

  • dongyou5271 2017-03-26 20:36
    关注
    • Please note the side-effect import of github.com/lib/pq
    • After this queries can be run by db.Query() or db.Exec()
    • https://golang.org/pkg/database/sql/#example_DB_Query
    • https://golang.org/pkg/database/sql/#pkg-examples

      import (
          _ "github.com/lib/pq"
          "database/sql"
          "fmt"
      )
      
      func MakeRedshfitConnection(username, password, host, port, dbName string) (*sql.DB, error) {
      
          url := fmt.Sprintf("sslmode=require user=%v password=%v host=%v port=%v dbname=%v",
              username,
              password,
              host,
              port,
              dbName)
      
          var err error
          var db *sql.DB
          if db, err = sql.Open("postgres", url); err != nil {
              return nil, fmt.Errorf("redshift connect error : (%v)"), err
          }
      
          if err = db.Ping(); err != nil {
              return nil, fmt.Errorf("redshift ping error : (%v)", err)
          }
          return db, nil
      }
      
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里