【发布时间】:2020-01-12 12:30:32
【问题描述】:
我不确定如何在 2dslice 中进行 postgres 查询 where (col1, col2)
我尝试了以下方法:
`
CREATE TABLE table2 (
id CHAR(27) NOT NULL,
lat FLOAT8 NOT NULL,
lon FLOAT8 NOT NULL,
PRIMARY KEY (id)
);
latlongdata := [][]float64{}
latlongdata = append(latlongdata, []float64{1.2, 2.3},)
latlongdata = append(latlongdata, []float64{1.3, 2.4},)
......................................
latlongdata = append(latlongdata, []float64{1.4, 2.5},)
fmt.Println(latlongdata)// prints [[1.2 2.3] [1.3 2.4] ....... [1.4 2.5]] (very long array)
Query: r.db.QueryContext(ctx,("SELECT id, lat, lon FROM table2 WHERE (lat, lon) IN $1", latlongdata,)
`
你能建议怎么做吗?
【问题讨论】:
-
我不认为
value1,value2 in ...是有效的sql。您可以将查询重写为 (lat=v1 and long=v2) 或 (lat=v2 and long=v4) 或 ... -
尝试通过像eversql.com/sql-syntax-check-validator这样的验证器运行你的sql语句
-
更新了我的问题。您能提出解决方案吗?
标签: postgresql go