4

如何在谷歌云扳手中查询数组?

我试过这个

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[]`
  };
4

1 回答 1

4

你会想要隐式地取消你的数组元素。举个例子

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"
于 2017-02-20T04:37:44.997 回答