我正在尝试使用github.com/lib/pq
和pq: 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
答案 0 :(得分:1)
尝试使用QuoteIdentifier
中的github.com/lib/pq
功能引用您的表名: