如何在谷歌云扳手中查询数组?
我试过这个
let query = {
sql:`SELECT id, name, description FROM articles WHERE lang = '` + req.swagger.params.lang.value + `' AND tags ARRAY['` + req.swagger.params.tag.value + `']::varchar[]`
};
如何在谷歌云扳手中查询数组?
我试过这个
let query = {
sql:`SELECT id, name, description FROM articles WHERE lang = '` + req.swagger.params.lang.value + `' AND tags ARRAY['` + req.swagger.params.tag.value + `']::varchar[]`
};
你会想要隐式地取消你的数组元素。举个例子
SELECT id, name, description
FROM articles as a, a.tags as single_tag
WHERE lang = "your lang value"
AND single_tag = "your tag value"
首先,我将数组 column 隐式地取消嵌套tags
到 column single_tag
。
其次,我将您的where
条款更改为与新single_tag
列相等
注意:如果标签中的多个值符合您的条件,您可以多次返回同一行。DISTINCT
只要您返回的列都不是数组或结构,您可以通过添加子句来解决此问题。例如:
SELECT DISTINCT id, name, description
FROM articles as a, a.tags as single_tag
WHERE lang = "your lang value"
AND single_tag = "your tag value"