我有一个customers带有name和features列的 postgresql 表。
features包含 jsonb 对象,例如{"featureA": true, "featureB": false, "featureC":true}
我想得到的是这些键的数组,features其中每个键的值都为真name,例如:
name | features
----------|---------------------
customerA | [featureA, featureC]
customerB | [featureB, featureC]
从这篇文章中,我了解到
SELECT key
FROM jsonb_each()
WHERE value = jsonb 'true'
是你如何获得真实的钥匙,但我该如何为我的桌子做到这一点customers?
就像是
SELECT array_agg(key)
FROM jsonb_each((select features from customers))
WHERE value = jsonb 'true'
返回SQL Error [21000]: ERROR: more than one row returned by a subquery used as an expression。
任何帮助,将不胜感激。