相关疑难解决方法(0)

自定义涉及数组的 jsonb 键排序顺序

我在 PostgreSQL 中有一个包含一些数据的表:

create table t2 (
    key jsonb,
    value jsonb
);

INSERT INTO t2(key, value)
 VALUES
 ('1', '"test 1"')
,('2', '"test 2"')
,('3', '"test 3"')
,('[]', '"test 4"')
,('[1]', '"test 5"')
,('[2]', '"test 6"')
,('[3]', '"test 7"')
,('[1, 2]', '"test 8"')
,('[1, 2, 3]', '"test 9"')
,('[1, 3]', '"test 10"')
,('[1,2,4]', '"test 11"')
,('[1, 2,4]', '"test 12"')
,('[1,3,13]', '"test 13"')
,('[1, 2, 15]', '"test 15"');
Run Code Online (Sandbox Code Playgroud)

我尝试像这样对这些行进行排序:

SELECT key FROM t2 order by key;
Run Code Online (Sandbox Code Playgroud)

结果是:

[]
1
2
3
[1] …
Run Code Online (Sandbox Code Playgroud)

postgresql index order-by array json

10
推荐指数
1
解决办法
1万
查看次数

标签 统计

array ×1

index ×1

json ×1

order-by ×1

postgresql ×1