我想过滤那些有gold徽章的行。我正在使用PG12,我使用它的新路径特性。
为了澄清,我有一个类似于这样的users_tbl表:
CREATE TABLE users_tbl (
ID serial NOT NULL PRIMARY KEY,
data jsonb NOT NULL
);
并让我们插入值:
INSERT INTO users_tbl (ID, data) values (1, '{"badges": ["gold", "silver"], "another_field": 1}');
我试图使下面的查询片段包含较少的重复数据,并使之看起来更优雅。你能告诉我吗?
SELECT
(select gender from jsonb_to_recordset(audience) as x(gender text[]) where x.gender is not null) as gender,
(select age from jsonb_to_recordset(audience) as x(age text[]) where x.age is not null) as age,
(select ethnicity from jsonb_to_recordset(audi
c.data是jsonb对象,如下所示:{programs:[{...},{...}]}
c.data->'programs'是jsonb数组,就像这个[{a:1},{b:2},{c:3,d:4}]或null
已经尝试过了:
SELECT p
FROM Clients c , jsonb_array_elements(c.data->'programs') p
或者这个
SELECT p
FROM Clients c , jsonb_array_elements(COALESCE(c.data->'programs','
我有一个包含4列的表availability:productcode、currency、bookableitems、summary。 bookableitems是JSONB。 我需要选择具有currency = 'USD'、productOptionCode = 'TG11'和ORDER BY [recommendedRetailPrice of ageBand = 'CHILD'] DESC的所有记录。 通过currency和productOptionCode进行选择很容易: SELECT *
FROM availability
WHERE
我希望将数据从一列(varchar)迁移到另一列(jsonb)。
Column | Type | Modifiers
------------+-----------------------------+--------------------------------------------------------
id | integer | not null default nextva
如何求和
用regex过滤的json列?
栏:
A.name:具有名称产品的Varchar
B.products:具有时间活性的JSON副产品
查询:
select
A.name as product,
sum(((REGEXP_MATCH(B.products->>'status', 'Active:.(.*?)\"'))[1])::float) as metric
from
tbl_accounts A
inner join tbl_products B on
A.identifier = B.identi
假设我在postgresql中存储了一些JSON,如下所示:
{"the": [0, 4], "time": [1, 5], "is": [2, 6], "here": [3], "now": [7]}
这是一个倒排的索引,显示每个单词的位置。
the time is here the time is now
我想把第二个例子中的文本放在一个单独的列中。我可以使用python转换倒置文本,如下所示:
def convert_index(inverted_index):
unraveled = {}