gpt4 book ai didi

json - PostgreSQL JSON 快速搜索(从任意键搜索值)

转载 作者:行者123 更新时间:2023-11-29 11:51:30 24 4
gpt4 key购买 nike

我尝试在 PostgreSQL JSONB 列中找到快速搜索功能的解决方案。要求是我们可以在任何 JSON 键中搜索值。

表结构:

CREATE TABLE entity ( id bigint NOT NULL, jtype character varying(64) NOT NULL, jdata jsonb, CONSTRAINT entity_pk PRIMARY KEY (id) )

思路是我们将不同类型的json存储在一张表中,jtype定义json实体类型,jdata-json数据,例如:

   jtype='person',jvalue = '{"personName":"John", "personSurname":"Smith", "company":"ABS Software", "position":"Programmer"}'
jtype='company', jvalue='{"name":"ABS Software", "address":"Somewhere in Alaska"}'

目标是进行快速搜索,用户可以键入“ABS”并找到两条记录 - 公司和在公司工作的人。

Oracle DB 的模拟函数包含:

SELECT jtype, jvalue FROM entity WHERE CONTAINS (jvalue, 'ABS') > 0;

GIN 索引只允许搜索键/值对

GIN indexes can be used to efficiently search for keys or key/value pairs occurring within a large number of jsonb documents (datums). Two GIN "operator classes" are provided, offering different performance and flexibility trade-offs.

https://www.postgresql.org/docs/current/static/datatype-json.html#JSON-INDEXING

最佳答案

https://github.com/postgrespro/jsquery尽管我以前没有使用过它,但它可能对您正在寻找的东西有用。

关于json - PostgreSQL JSON 快速搜索(从任意键搜索值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43236959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com