jjzjj

postgres

全部标签

postgresql - 如何使用 go pg CRUD Postgres Point 数据类型

我正在使用Point数据类型在Postgres数据库中存储坐标。如何将Point数据类型映射到Golang数据类型?我没有找到任何相同的文档。 最佳答案 go-pg没有对点类型的本地支持(从PostGIS开始)。我所做的立交桥(可能不是最好的解决方案,但我确实设法让它工作)是在我的模型上放置单独的纬度和经度字段,并在查询本身上使用ColumnExpr使用ST_X(对于经度)和ST_Y(对于纬度,不要忘记)获取单个值。型号:typeMyModelstruct{IDint64NamestringLocationLatfloat64Loc

postgresql - Gorm 无法连接到本地 postgres 数据库

我是GoLang的新手,在将我的Go网络服务器与Postgres数据库连接时遇到了问题。有人可以告诉我我在这里做错了什么吗?顺便说一句,所有这些凭据都是正确的。用户存在,密码正确,数据库存在且属于用户。packageappimport("github.com/jinzhu/gorm"_"github.com/jinzhu/gorm/dialects/postgres")funcconnectDB(){db,err:=gorm.Open("postgres","host=localhostport=5432user=power_userdbname=local_dbpassword=po

postgresql - 将字符串插入 jsonb 类型的 postgres

我的结构看起来像:typestruct1struct{idintcommentstringextrastring}我的表架构如下所示:createtabledeal(idbigserial,commentvarchar(75),extrajsonb)我想将[]struct1转储到PostgresDB“交易”。我生成准备好的语句的函数如下所示:funcBulkInsert(str[]struct1,ctxcontext.Context)string{log.Debug("insertingrecordstoDB")query:=fmt.Sprintf(`insertintodeal(%s

postgresql - 如何将 Google App Engine (Flex) Go 应用程序连接到 Google Cloud Postgres 实例

我正在使用Go构建应用程序并使用GoogleAppEngine进行部署。我已经在GoogleCloud上设置了一个PostgreSQL实例,启用了API并使用本地计算机上的SQL代理成功连接到它,包括本地PSequel客户端和我的应用程序。但是,当我执行gcloudappdeploy时,出现此错误:ERROR:(gcloud.app.deploy)ErrorResponse:[9]Applicationstartuperror:panic:dialunix/cloudsql/sapling:europe-west1:sapling/.s.PGSQL.5432:connect:nosuc

postgresql - Postgres 选择 WHERE col1, col2 IN 与 2d golang slice

我不确定如何使postgres查询2dslice中的where(col1,col2)我尝试了以下方法:`CREATETABLEtable2(idCHAR(27)NOTNULL,latFLOAT8NOTNULL,lonFLOAT8NOTNULL,PRIMARYKEY(id));latlongdata:=[][]float64{}latlongdata=append(latlongdata,[]float64{1.2,2.3},)latlongdata=append(latlongdata,[]float64{1.3,2.4},)..............................

postgresql - golang 中的 postgres 查询

我不确定如何在2dslice中的(col1,col2)位置进行postgres查询我尝试了以下方法:CREATETABLEtable2(idCHAR(27)NOTNULL,latFLOAT8NOTNULL,lonFLOAT8NOTNULL,PRIMARYKEY(id));latlongdata:=[][]float64{}latlongdata=append(latlongdata,[]float64{1.2,2.3},)latlongdata=append(latlongdata,[]float64{1.3,2.4},)................................

sql - 使用 Postgres 时为 "Operator does not exist: integer =?"

我在go的database/sql包提供的QueryRow方法中调用了一个简单的SQL查询。import("github.com/codegangsta/martini""github.com/martini-contrib/render""net/http""database/sql""fmt"_"github.com/lib/pq"))typeUserstruct{Namestring}funcShow(db*sql.DB,paramsmartini.Params){id:=params["id"]row:=db.QueryRow("SELECTnameFROMusersWHERE

postgresql - Go Hood 保存到 Postgres,但不确定在哪里

我有一个采用http.Request的SaveRequest方法,然后据推测将它(现在只是路径)保存到postgres数据库:func(logger*PostgresLogger)SaveRequest(req*http.Request){os.Stdout.Write([]byte("SavingtoPGDB\n"))request:=db.Requests{Path:req.URL.Path}transaction:=logger.dbConnection.Begin()Id,saveError:=transaction.Save(&request)ifsaveError!=nil

postgresql - Golang、postgres事务: pq: unexpected transaction status in a failed transaction

Go:v1.3db:postgres使用lib/pq我有一个更新postgres数据库的应用程序。postgres数据库是使用pgbouncer设置的。因此,通过事件连接,我有运行插入和更新的代码。这是插入代码:func(sitemap*SiteMapData)InsertSiteMap(dbConnection*sql.DB)(int64,error){tx,err:=dbConnection.Begin()iferr!=nil{l4g.Error("InsertSiteMap:couldnotbeingtransaction:%v",err)return0,err}result,e

postgres 数组的正则表达式

我正在使用不支持postgres数组的ORM,所以我正在尝试做一些hack来添加“支持”。目前我必须将postgres数组字符串转换为编程语言数组。postgres数组字符串表示示例:{"bla,bla",bla,"bubu",bu}所以如果有空格,postgres会自动添加引号,如果没有,则元素没有引号。您将使用什么正则表达式从中获取数组?所以结果应该是:array:=[]{"bla,bla","bla","bubu","bu"}我正在使用Go。数组是一维的,所以类似于:创建表测试(一些文字[]); 最佳答案 我不熟悉golang