-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathzson.sql
50 lines (31 loc) · 1.14 KB
/
zson.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
CREATE EXTENSION zson;
SELECT zson_extract_strings('true');
SELECT zson_extract_strings('"aaa"');
SELECT zson_extract_strings('["some", ["dummy", "array"], 456, false]');
SELECT zson_extract_strings('{"IP":"10.0.0.3","Roles":["master", "slave"]}');
CREATE TABLE nocompress(x jsonb);
INSERT INTO nocompress VALUES
('true'),
('123'),
('"aaa"'),
('["some", ["dummy", "array"], 456, false]'),
('
[
{"ModifyIndex":1,"IP":"10.0.0.1","Roles":["master"]},
{"ModifyIndex":2,"IP":"10.0.0.2","Roles":["slave"]},
{"ModifyIndex":3,"IP":"10.0.0.3","Roles":["master", "slave"]}
]
');
SELECT zson_learn('{{"nocompress", "x"}}');
SELECT dict_id, word FROM zson_dict ORDER BY dict_id, word COLLATE "C";
SELECT zson_learn('{{"nocompress", "x"}}', 10000, 1, 128, 1);
SELECT dict_id, word FROM zson_dict ORDER BY dict_id, word COLLATE "C";
SELECT '{"aaa": "ololo"}'::zson;
SELECT '{"aaa": "ololo"}'::zson -> 'aaa';
CREATE TABLE zson_test(x zson);
INSERT INTO zson_test VALUES('{"aaa":123}' :: jsonb);
SELECT dict_id, word FROM zson_dict ORDER BY dict_id, word COLLATE "C";
SELECT x :: jsonb FROM zson_test;
DROP TABLE zson_test;
DROP TABLE nocompress;
DROP EXTENSION zson;