postgresql在数组上使用like
我有两个表“标签”和“别名”,其中多个别名可以映射到同一标签。我正在尝试进行标签搜索,并且可以轻松地搜索使用类似搜索查询的标签,但我也想与标签的任何别名进行搜索查询匹配。
这就是我目前拥有的:
SELECT tags.*, json_agg(DISTINCT aliases.*) AS aliases
FROM tags
FULL JOIN aliases ON aliases.tag = tags.tag
WHERE tags.tag LIKE $1 || '%'
GROUP BY tags.tag
如何在每个别名(在JSON阵列别名中)使用?
I have two tables, "tags" and "aliases", where multiple aliases can map to the same tag. I am trying to do a tag search, and I can easily search for tags matching a search query using LIKE, but I also want to make the search query match against any of the aliases of the tag.
This is what I currently have:
SELECT tags.*, json_agg(DISTINCT aliases.*) AS aliases
FROM tags
FULL JOIN aliases ON aliases.tag = tags.tag
WHERE tags.tag LIKE $1 || '%'
GROUP BY tags.tag
How do I use LIKE on each of the aliases (in the json array aliases)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是答案,归功于Reddit上的U/Davidgjohnston。您可以通过添加一个子查询来做到这一点。
This was the answer, credit goes to u/DavidGJohnston on Reddit. You can do this by adding an EXISTS subquery.