Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 类型化jsonb数组查询_Postgresql_Nestjs_Jsonb_Typeorm - Fatal编程技术网

Postgresql 类型化jsonb数组查询

Postgresql 类型化jsonb数组查询,postgresql,nestjs,jsonb,typeorm,Postgresql,Nestjs,Jsonb,Typeorm,我试图查询一个jsonb数组 列中的示例数据 [{"entityId": "1ebi", "entityType": "user", "mode": "editor"}, {"entityId": "F13t", "entityType": "team", "mode": &qu

我试图查询一个jsonb数组

列中的示例数据

[{"entityId": "1ebi", "entityType": "user", "mode": "editor"}, {"entityId": "F13t", "entityType": "team", "mode": "viewer"}]
实体定义

@Column({ name: 'details', type: 'jsonb' })
public details: {entityId: string, entityType: string, mode: string}[]; 
这个查询似乎不起作用。我看到这个后就试过了。但我的数据是一个JSON数组

 this.workbookPermissionRepository
      .createQueryBuilder('wp')
      .select()
      .where('wp.details ::jsonb @> :details', {
        details: {
          entityType: IPermissionEntityTypes.USER,
          entityId: user.slug,
          mode: Not(IPermissionSharingModes.NO_ACCESS),
        },
      })
      .printSql()
      .getMany();

我没有在打字机上找到任何东西。欢迎任何建议。

在json数组上查询Postgres时的语法要求将查询的右侧用括号括起来。在这种情况下,请尝试将查询包装在括号中,并按如下方式对其进行字符串化:

 this.workbookPermissionRepository
  .createQueryBuilder('wp')
  .select()
  .where('wp.details ::jsonb @> :details', {
    details: JSON.stringify([{
      entityType: IPermissionEntityTypes.USER,
      entityId: user.slug,
      mode: Not(IPermissionSharingModes.NO_ACCESS),
    }])
  })
  .printSql()
  .getMany();
下面是一篇类似的文章,可以帮助解释基本的Postgres查询: