gpt4 book ai didi

postgresql - Postgres 选择 WHERE col1, col2 IN 与 2d golang slice

转载 作者:数据小太阳 更新时间:2023-10-29 03:18:13 26 4
gpt4 key购买 nike

我不确定如何使 postgres 查询 2dslice 中的 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,)

`

你能建议怎么做吗?

最佳答案

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

或创建 latlongdata 并将其插入到临时表中然后

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

关于postgresql - Postgres 选择 WHERE col1, col2 IN 与 2d golang slice ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57876044/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com