草庐IT

postgreSql

全部标签

postgresql - 如何一次性将多行插入 postgresQL

是否可以一次向Postgres数据库中插入多行?有人可以建议是否有办法将一片slice插入数据库。我为每一行创建了一个slice,并通过将所有行slice附加到它来创建另一个slice(多行)。如何将slice(多行)插入数据库?当我创建行slice时,我使用的是row:=[]interface{}{}。因为我在每一行中都有字符串和int字段。看来我插入数据时出现错误,错误是unsupportedtype[]interface{},asliceofinterface实现:rowdata:=[]interface{}{}row:=[]interface{}{data.ScenarioUU

postgresql - 如何一次性将多行插入 postgresQL

是否可以一次向Postgres数据库中插入多行?有人可以建议是否有办法将一片slice插入数据库。我为每一行创建了一个slice,并通过将所有行slice附加到它来创建另一个slice(多行)。如何将slice(多行)插入数据库?当我创建行slice时,我使用的是row:=[]interface{}{}。因为我在每一行中都有字符串和int字段。看来我插入数据时出现错误,错误是unsupportedtype[]interface{},asliceofinterface实现:rowdata:=[]interface{}{}row:=[]interface{}{data.ScenarioUU

sql - Golang 在 postgres 中包装查询执行

我正在使用以下代码在我为学习Go而构建的API中包装对postgres数据库的查询执行。funcQueryDB(qstringstring)(*sql.Rows){psqlInfo:=fmt.Sprintf("host=%sport=%duser=%sdbname=%ssslmode=disable",host,port,user,dbname)db,err:=sql.Open("postgres",psqlInfo)iferr!=nil{panic(err)}deferdb.Close()//Pingmethodopenstheconnectionerr=db.Ping()iferr

sql - Golang 在 postgres 中包装查询执行

我正在使用以下代码在我为学习Go而构建的API中包装对postgres数据库的查询执行。funcQueryDB(qstringstring)(*sql.Rows){psqlInfo:=fmt.Sprintf("host=%sport=%duser=%sdbname=%ssslmode=disable",host,port,user,dbname)db,err:=sql.Open("postgres",psqlInfo)iferr!=nil{panic(err)}deferdb.Close()//Pingmethodopenstheconnectionerr=db.Ping()iferr

database - 为用户无缝地将数据库打包到应用程序中

我想创建一个使用关系数据库的桌面应用程序(例如postgres-假设我最好的情况是在此应用程序中使用postgres)。我希望用户不知道数据库。目前,我必须将postgres安装到我的本地计算机并让我的应用程序与之通信。我正在使用Go。我怎样才能避免这种情况? 最佳答案 您正在寻找一个嵌入式数据库。Thisisn'tanidealjobforPostgreSQL,但是youcanuseitthatwaywithabitofcare.请不要捆绑安装程序并在无人值守的情况下运行它。稍后去安装PostgreSQL的用户会很困惑,因为他们看

database - 为用户无缝地将数据库打包到应用程序中

我想创建一个使用关系数据库的桌面应用程序(例如postgres-假设我最好的情况是在此应用程序中使用postgres)。我希望用户不知道数据库。目前,我必须将postgres安装到我的本地计算机并让我的应用程序与之通信。我正在使用Go。我怎样才能避免这种情况? 最佳答案 您正在寻找一个嵌入式数据库。Thisisn'tanidealjobforPostgreSQL,但是youcanuseitthatwaywithabitofcare.请不要捆绑安装程序并在无人值守的情况下运行它。稍后去安装PostgreSQL的用户会很困惑,因为他们看

database - GO 打开本地 postgres 连接

我的postgres在Mac上的本地端口5432上运行它上面有一个名为test的数据库,这个数据库中有一个名为test_table的表我正在尝试使用GO连接到它。导入:"database/sql"_"github.com/lib/pq"主要内容:db,err:=sql.Open("postgres","postgres://user:@localhost:5432/test")iferr!=nil{log.Println(err)}deferdb.Close()iferr2:=db.Ping();err2!=nil{fmt.Println("Failedtokeepconnection

database - GO 打开本地 postgres 连接

我的postgres在Mac上的本地端口5432上运行它上面有一个名为test的数据库,这个数据库中有一个名为test_table的表我正在尝试使用GO连接到它。导入:"database/sql"_"github.com/lib/pq"主要内容:db,err:=sql.Open("postgres","postgres://user:@localhost:5432/test")iferr!=nil{log.Println(err)}deferdb.Close()iferr2:=db.Ping();err2!=nil{fmt.Println("Failedtokeepconnection

postgresql - 使用 docker-compose 时如何从 golang 应用程序连接到 postgres?

我的docker-compose文件version:"2"services:db:restart:alwaysimage:postgres:latestports:-"5435:5432"environment:POSTGRES_PASSWORD:passwordPOSTGRES_USER:userPOSTGRES_DB:dbadminer:web:image:golang:1.7working_dir:/go/src/appcommand:gorunbot.goports:-"3000:3000"volumes:-./bot:/go/src/applinks:-dbenvironme

postgresql - 使用 docker-compose 时如何从 golang 应用程序连接到 postgres?

我的docker-compose文件version:"2"services:db:restart:alwaysimage:postgres:latestports:-"5435:5432"environment:POSTGRES_PASSWORD:passwordPOSTGRES_USER:userPOSTGRES_DB:dbadminer:web:image:golang:1.7working_dir:/go/src/appcommand:gorunbot.goports:-"3000:3000"volumes:-./bot:/go/src/applinks:-dbenvironme