Postgres:json数组包含的地方(ids的子选择查询)

时间:2016-11-28 17:21:23

标签: sql postgresql

我试图整理一个postgres查询,该查询检查具有id数组的json字段是否包含来自subselect查询的任何id。例如:典型的user表如下所示:

User
  .id           // Int     --> 1
  .first_name   // String  --> Joe
  .last_name    // String  --> Doe
  .tags         // JSON    --> [4, 9, 21, 26, 39]

标签表是这样的:

Tags
  .id           // Int     --> 1
  .name         // String  --> "Peaches"

但无论如何,这是我想要实现的目标:

select u.id, u.first_name from users u 
  where u.tags = any( array (
    select t.id from tags t where t.name in ('Peaches', 'Nuts and Honey', 'Flour')
));

这会导致以下错误: No function matches the given name and argument types. You might need to add explicit type casts.

关于如何解决这个问题的任何想法都会很棒!

0 个答案:

没有答案
相关问题