草庐IT

postgresql_psycopg

全部标签

postgresql - golang postgres 连接错误太多

我是Golang/Postgres的新手,我正在做一些测试并收到一个pq:sorry,toomanyclientsalready错误。我的postgres实例设置为最多100个连接,我在此代码中收到该错误fori:=0;i我通常可以插入大约60到70个插入然后我得到那个错误。所有连接都来自for循环中的那个样本。我做错了什么,这是我的完整代码。据我所知,1个连接可以容纳许多不同的查询,所以我不知道为什么它只给我60到70个插入然后得到错误。funcInsert_Stream(whttp.ResponseWriter,r*http.Request){wg:=sync.WaitGroup{

postgresql - 如何在 golang 中使用 .Format 将 time.Time 对象转换为格式化字符串?

我目前正在尝试从我的SQL数据库中获取一个time.Time对象,并将检索到的值转换为格式化字符串,如下所示:TIME_FORMAT:="%Y-%m-%dT%H:%M:%S"这是我在Python中用来做同样事情的格式,但我知道它不适合go。我已经从数据库中获取了值,现在只需要对其进行格式化。请注意,我已将ccc.Ia_date定义为interface{}类型,因为数据库中的此值可能为空。这是我的代码片段:fmt.Println(reflect.TypeOf(ccc.Ia_date))//givesmetime.Timet:=ccc.Ia_date//whichprintsas:2016

postgresql - 如何从go app查看postgresql "raise notice"

我正在用go编写小应用程序。现在我需要在应用程序控制台中记录postgres“raisenotice”消息。我没有找到postgresql在*sql.Conn中引发消息的地方(我使用go/sql和lib/pq驱动程序)例子,createfunctionshow_mes()returnsintas$$beginraisenotice'testmessagefrompg';return1;end$$languageplpgsql;我从goapp调用这个函数并可以得到结果。但是我如何从goapp访问消息“来自pg的测试消息”?在用Node编写的当前版本中,我们在控制台中记录消息以进行调试:谢

postgresql - golang/pq pq : operator does not exist: bigint = text

query:="WITHb(ColA,ColB)AS(VALUES($1,$2))UPDATEschema_name.table_nameASaSETColC=b.ColBFROMbWHEREa.ColA=b.ColAANDa.ColB=b.ColB"res,err:=db.Exec(query,1,1)上述代码失败并出现以下错误:pq:operatordoesnotexist:bigint=text“ColC”是BIGINT类型。根据我的调查,驱动程序将值作为文本而不是整数插入。问题:https://github.com/lib/pq/issues/582

postgresql - Golang GORM 中列的自动迁移问题

自动迁移问题(我认为)。我可以通过psql控制台得出该列不存在的结论。我可以通过终端/控制台/SQL手动插入该列,但更喜欢通过自动迁移来解决此问题。感谢您的阅读和/或行动。终端输出:启动Web服务器:“(pq:列“password_hash”包含空值值(value)观)”提交POST:“(pq:关系“accounts”的列“password_hash”不存在)” 最佳答案 来源:JonCalhoun资源:https://www.usegolang.com/"...theshortansweristhatautomigratefail

postgresql - 转到-pg-pg : can't find dst value for model id =","

正在获取pg:找不到模型id=","的dst值我定义了以下模型//omittingfieldswhichdon'tseemrelevanttotheissue//correspondingqueriesalsoshortenedasappropriatetypeGrProductstruct{tableNamestruct{}`sql:"gr_product"`IDint64Namestring//fk:Product,joinFK:Categorygivensothatjoinsaremadeoncategory_idandproduct_idwithgr_product_categ

postgresql - go-gorm,postgres : simple inserts return error

由于最近的炒作,我正在尝试做简单的插入,试图评估Postgres的有用性。我是一个mongoDB的人。这就是我想要做的:db,e:=gorm.Open("postgres",fmt.Sprintf("host=%suser=%sdbname=%spassword=%ssslmode=disable",pgHost,pgUser,pgDatabase,pgPass))ife!=nil{log.Fatal(e.Error())}deferdb.Close()db.AutoMigrate(&model.Customer{},&model.Email{},&model.Address{},&m

postgresql - 使用 Postgres 的 Golang UPDATE 专栏

假设我有一个表employments和一个结构EmploymenttypeEmploymentstruct{IDint`json:"id"`Created_atstring`json:"created_at"`Updated_atstring`json:"updated_at"`Educationstring`json:"education"`Jobstring`json:"job"`Positionstring`json:"position"`Business_phonestring`json:"business_phone"`Next_paydaystring`json:"next

postgresql - 使用 Postgres 和 GO 强制执行 "lock"

我是Postgres的新手,所以这可能是显而易见的(或者非常困难,我不确定)。我想强制一个表或行一次至少“锁定”几秒钟。这将导致第二个操作“等待”。我正在使用golang和“github.com/lib/pq”来与数据库交互。我需要这个的原因是因为我正在做一个监控postgresql的项目。谢谢你的帮助。 最佳答案 您还可以使用select...forupdate来锁定一行或多行事务的长度。基本上,它就像:begin;select*fromfoowherequatloos=100forupdate;updatefoosetfeens

postgresql - Golang Postgres 如何将表转储为 JSON

我正在尝试为Go1.9中的多个表(一次一个表)运行此命令:COPY(selectrow_to_json(foo)FROM(SELECT*FROMbar)foo)TO'/tmp/bar.json';这可能吗?似乎与lib/pg一起,但事实并非如此。使用go-pg,我总是会耗尽内存,因为它会先将所有内容缓冲到内存中。从命令提示符执行此操作效果很好。我宁愿使用Go的PG库,也不愿让它在命令提示符下运行。简而言之,我试图将整个表转储到它们自己的文件中的JSON中。有人成功过吗?谢谢!编辑:因为lb/pg根本不支持这个,所以我使用pg-go。这是代码:varbufbytes.Buffer_,er