转到数据库/ sql更改表名称的大小写

时间:2016-03-27 19:38:45

标签: postgresql go

我正在尝试使用github.com/lib/pqpq: relation "itemprices_itemsale" does not exist Postgres驱动程序查询数据库。我遇到的错误是:

rows, err := db.Query("SELECT * FROM \"itemPrices_itemsale\" LIMIT 10")

但是查看我的查询:

var table = "itemPrices_itemsale"
rows, err := db.Query(fmt.Sprintf("SELECT * FROM %s LIMIT 10", pq.QuoteIdentifier(table)))

你会注意到首都' P'在表名中。我已经学会了形式,如果没有引用,Postgres会将名称折叠成小写。我引用了我的表名,所以我不太清楚为什么会这样。我很确定这是问题,因为我能够使用类似Python程序中的表名查询表,并且一切都按预期工作。

更新: 使用@ JohnWeldon的建议:

display logo.gif

1 个答案:

答案 0 :(得分:1)

尝试使用QuoteIdentifier中的github.com/lib/pq功能引用您的表名:

https://godoc.org/github.com/lib/pq#QuoteIdentifier