Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.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
Sql 如何在Postgres中获取hstore值满足返回键的特定条件的行?_Sql_Postgresql_Hstore - Fatal编程技术网

Sql 如何在Postgres中获取hstore值满足返回键的特定条件的行?

Sql 如何在Postgres中获取hstore值满足返回键的特定条件的行?,sql,postgresql,hstore,Sql,Postgresql,Hstore,我有一篇专栏文章。现在,我想对满足hstore值特定条件的行进行筛选—不知道键。 例如 现在我想获取所有hstore值为0的行。并列出键。第一次将存储项转换为CTE中的行: with aspects as (select ..., (each("attributes")).* from mainTable), 函数的each()为您提供两列,分别命名为“key”和“value”。 现在将此CTE与所需条件一起使用,连接到主表并将键收集回数组: select ..., array_agg

我有一篇专栏文章。现在,我想对满足hstore值特定条件的行进行筛选—不知道键。 例如


现在我想获取所有hstore值为0的行。并列出键。

第一次将存储项转换为CTE中的行:

with aspects as (select ..., (each("attributes")).*
    from mainTable),
函数的each()为您提供两列,分别命名为“key”和“value”。 现在将此CTE与所需条件一起使用,连接到主表并将键收集回数组:

select ..., array_agg(key) as fulfilled_aspects
    from aspects a join mainTable m on m.id = a.id
    where a.value = '0'
结果将是一行,其中包含“Completed_aspects”数组列,其中包含: “aspect2,aspect4”

您还可以使用后者作为CTE,将main表中的更多列添加到结果中

select ..., array_agg(key) as fulfilled_aspects
    from aspects a join mainTable m on m.id = a.id
    where a.value = '0'