doutuobao9736 2019-09-10 17:57
浏览 35

Postgres选择带有2D Golang切片的WHERE col1,col2 IN

I am not sure how to make postgres query where (col1, col2) in 2dslice

I have tried the following:

`

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,)

`

Can you please suggest how to do it?

  • 写回答

1条回答 默认 最新

  • doob0526 2019-09-11 00:54
    关注
    Query: r.db.QueryContext(ctx,("SELECT id, lat, long FROM table2 WHERE lat, long IN (select $1, $2 union select $3, $4)", latlongdata[0][0], latlongdata[0][1], latlongdata[1][0], latlongdata[1][1])
    

    or create and insert latlongdata into a temp table then

    WHERE lat, long IN (select filed1, field2 from temptable)
    
    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100