-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathzson.out
127 lines (115 loc) · 2.92 KB
/
zson.out
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
CREATE EXTENSION zson;
SELECT zson_extract_strings('true');
zson_extract_strings
----------------------
{}
(1 row)
SELECT zson_extract_strings('"aaa"');
zson_extract_strings
----------------------
{aaa}
(1 row)
SELECT zson_extract_strings('["some", ["dummy", "array"], 456, false]');
zson_extract_strings
----------------------
{some,dummy,array}
(1 row)
SELECT zson_extract_strings('{"IP":"10.0.0.3","Roles":["master", "slave"]}');
zson_extract_strings
----------------------------------
{IP,Roles,10.0.0.3,master,slave}
(1 row)
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"}}');
zson_learn
-------------------------------------------------------------------------------
Done! Run " select * from zson_dict where dict_id = 0; " to see a dictionary.
(1 row)
SELECT dict_id, word FROM zson_dict ORDER BY dict_id, word COLLATE "C";
dict_id | word
---------+-------------
0 | IP
0 | ModifyIndex
0 | Roles
0 | master
0 | slave
(5 rows)
SELECT zson_learn('{{"nocompress", "x"}}', 10000, 1, 128, 1);
zson_learn
-------------------------------------------------------------------------------
Done! Run " select * from zson_dict where dict_id = 1; " to see a dictionary.
(1 row)
SELECT dict_id, word FROM zson_dict ORDER BY dict_id, word COLLATE "C";
dict_id | word
---------+-------------
0 | IP
0 | ModifyIndex
0 | Roles
0 | master
0 | slave
1 | 10.0.0.1
1 | 10.0.0.2
1 | 10.0.0.3
1 | IP
1 | ModifyIndex
1 | Roles
1 | aaa
1 | array
1 | dummy
1 | master
1 | slave
1 | some
(17 rows)
SELECT '{"aaa": "ololo"}'::zson;
zson
------------------
{"aaa": "ololo"}
(1 row)
SELECT '{"aaa": "ololo"}'::zson -> 'aaa';
?column?
----------
"ololo"
(1 row)
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";
dict_id | word
---------+-------------
0 | IP
0 | ModifyIndex
0 | Roles
0 | master
0 | slave
1 | 10.0.0.1
1 | 10.0.0.2
1 | 10.0.0.3
1 | IP
1 | ModifyIndex
1 | Roles
1 | aaa
1 | array
1 | dummy
1 | master
1 | slave
1 | some
(17 rows)
SELECT x :: jsonb FROM zson_test;
x
--------------
{"aaa": 123}
(1 row)
DROP TABLE zson_test;
DROP TABLE nocompress;
DROP EXTENSION zson;