Initial revision
[hstore.git] / sql / hstore.sql
1 \set ECHO none
2 \i hstore.sql
3 set escape_string_warning=off;
4 \set ECHO all
5 --hstore;
6
7 select ''::hstore;
8 select 'a=>b'::hstore;
9 select ' a=>b'::hstore;
10 select 'a =>b'::hstore;
11 select 'a=>b '::hstore;
12 select 'a=> b'::hstore;
13 select '"a"=>"b"'::hstore;
14 select ' "a"=>"b"'::hstore;
15 select '"a" =>"b"'::hstore;
16 select '"a"=>"b" '::hstore;
17 select '"a"=> "b"'::hstore;
18 select 'aa=>bb'::hstore;
19 select ' aa=>bb'::hstore;
20 select 'aa =>bb'::hstore;
21 select 'aa=>bb '::hstore;
22 select 'aa=> bb'::hstore;
23 select '"aa"=>"bb"'::hstore;
24 select ' "aa"=>"bb"'::hstore;
25 select '"aa" =>"bb"'::hstore;
26 select '"aa"=>"bb" '::hstore;
27 select '"aa"=> "bb"'::hstore;
28
29 select 'aa=>bb, cc=>dd'::hstore;
30 select 'aa=>bb , cc=>dd'::hstore;
31 select 'aa=>bb ,cc=>dd'::hstore;
32 select 'aa=>bb, "cc"=>dd'::hstore;
33 select 'aa=>bb , "cc"=>dd'::hstore;
34 select 'aa=>bb ,"cc"=>dd'::hstore;
35 select 'aa=>"bb", cc=>dd'::hstore;
36 select 'aa=>"bb" , cc=>dd'::hstore;
37 select 'aa=>"bb" ,cc=>dd'::hstore;
38
39 select 'aa=>null'::hstore;
40 select 'aa=>NuLl'::hstore;
41 select 'aa=>"NuLl"'::hstore;
42
43 select '\\=a=>q=w'::hstore;
44 select '"=a"=>q\\=w'::hstore;
45 select '"\\"a"=>q>w'::hstore;
46 select '\\"a=>q"w'::hstore;
47
48 select ''::hstore;
49 select '        '::hstore;
50
51 -- -> operator
52
53 select 'aa=>b, c=>d , b=>16'::hstore->'c';
54 select 'aa=>b, c=>d , b=>16'::hstore->'b';
55 select 'aa=>b, c=>d , b=>16'::hstore->'aa';
56 select ('aa=>b, c=>d , b=>16'::hstore->'gg') is null;
57 select ('aa=>NULL, c=>d , b=>16'::hstore->'aa') is null;
58
59 -- exists/defined
60
61 select isexists('a=>NULL, b=>qq', 'a');
62 select isexists('a=>NULL, b=>qq', 'b');
63 select isexists('a=>NULL, b=>qq', 'c');
64 select isdefined('a=>NULL, b=>qq', 'a');
65 select isdefined('a=>NULL, b=>qq', 'b');
66 select isdefined('a=>NULL, b=>qq', 'c');
67
68 -- delete 
69
70 select delete('a=>1 , b=>2, c=>3'::hstore, 'a');
71 select delete('a=>null , b=>2, c=>3'::hstore, 'a');
72 select delete('a=>1 , b=>2, c=>3'::hstore, 'b');
73 select delete('a=>1 , b=>2, c=>3'::hstore, 'c');
74 select delete('a=>1 , b=>2, c=>3'::hstore, 'd');
75
76 -- ||
77 select 'aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f';
78 select 'aa=>1 , b=>2, cq=>3'::hstore || 'aq=>l';
79 select 'aa=>1 , b=>2, cq=>3'::hstore || 'aa=>l';
80 select 'aa=>1 , b=>2, cq=>3'::hstore || '';
81 select ''::hstore || 'cq=>l, b=>g, fg=>f';
82
83 -- =>
84 select 'a=>g, b=>c'::hstore || ( 'asd'=>'gf' );
85 select 'a=>g, b=>c'::hstore || ( 'b'=>'gf' );
86
87 -- keys/values
88 select akeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
89 select akeys('""=>1');
90 select akeys('');
91 select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
92 select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
93 select avals('""=>1');
94 select avals('');
95
96 select * from skeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
97 select * from skeys('""=>1');
98 select * from skeys('');
99 select * from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
100 select *, svals is null from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
101 select * from svals('""=>1');
102 select * from svals('');
103
104 select * from each('aaa=>bq, b=>NULL, ""=>1 ');
105
106 -- @
107 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL';
108 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, c=>NULL';
109 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>NULL, g=>NULL';
110 select 'a=>b, b=>1, c=>NULL'::hstore @ 'g=>NULL';
111 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>c';
112 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b';
113 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>NULL';
114 select 'a=>b, b=>1, c=>NULL'::hstore @ 'a=>b, c=>q';
115
116 CREATE TABLE testhstore (h hstore);
117 \copy testhstore from 'data/hstore.data'
118
119 select count(*) from testhstore where h @ 'wait=>NULL';
120 select count(*) from testhstore where h @ 'wait=>CC';
121 select count(*) from testhstore where h @ 'wait=>CC, public=>t';
122
123 create index hidx on testhstore using gist(h);
124 set enable_seqscan=off;
125
126 select count(*) from testhstore where h @ 'wait=>NULL';
127 select count(*) from testhstore where h @ 'wait=>CC';
128 select count(*) from testhstore where h @ 'wait=>CC, public=>t';
129
130 select count(*) from (select (each(h)).key from testhstore) as wow ;
131 select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key;