| 1 |
CREATE EXTENSION hstore; |
| 2 |
|
| 3 |
-- Check whether any of our opclasses fail amvalidate |
| 4 |
SELECT amname, opcname |
| 5 |
FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod |
| 6 |
WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid); |
| 7 |
|
| 8 |
set escape_string_warning=off; |
| 9 |
|
| 10 |
--hstore; |
| 11 |
|
| 12 |
select ''::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 '"a"=>"b"'::hstore; |
| 19 |
select ' "a"=>"b"'::hstore; |
| 20 |
select '"a" =>"b"'::hstore; |
| 21 |
select '"a"=>"b" '::hstore; |
| 22 |
select '"a"=> "b"'::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 |
select '"aa"=>"bb"'::hstore; |
| 29 |
select ' "aa"=>"bb"'::hstore; |
| 30 |
select '"aa" =>"bb"'::hstore; |
| 31 |
select '"aa"=>"bb" '::hstore; |
| 32 |
select '"aa"=> "bb"'::hstore; |
| 33 |
|
| 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 |
select 'aa=>bb , "cc"=>dd'::hstore; |
| 39 |
select 'aa=>bb ,"cc"=>dd'::hstore; |
| 40 |
select 'aa=>"bb", cc=>dd'::hstore; |
| 41 |
select 'aa=>"bb" , cc=>dd'::hstore; |
| 42 |
select 'aa=>"bb" ,cc=>dd'::hstore; |
| 43 |
|
| 44 |
select 'aa=>null'::hstore; |
| 45 |
select 'aa=>NuLl'::hstore; |
| 46 |
select 'aa=>"NuLl"'::hstore; |
| 47 |
|
| 48 |
select e'\\=a=>q=w'::hstore; |
| 49 |
select e'"=a"=>q\\=w'::hstore; |
| 50 |
select e'"\\"a"=>q>w'::hstore; |
| 51 |
select e'\\"a=>q"w'::hstore; |
| 52 |
|
| 53 |
select ''::hstore; |
| 54 |
select ' '::hstore; |
| 55 |
|
| 56 |
-- invalid input |
| 57 |
select ' =>null'::hstore; |
| 58 |
select 'aa=>"'::hstore; |
| 59 |
|
| 60 |
-- also try it with non-error-throwing API |
| 61 |
select pg_input_is_valid('a=>b', 'hstore'); |
| 62 |
select pg_input_is_valid('a=b', 'hstore'); |
| 63 |
select * from pg_input_error_info('a=b', 'hstore'); |
| 64 |
select * from pg_input_error_info(' =>b', 'hstore'); |
| 65 |
|
| 66 |
|
| 67 |
-- -> operator |
| 68 |
|
| 69 |
select 'aa=>b, c=>d , b=>16'::hstore->'c'; |
| 70 |
select 'aa=>b, c=>d , b=>16'::hstore->'b'; |
| 71 |
select 'aa=>b, c=>d , b=>16'::hstore->'aa'; |
| 72 |
select ('aa=>b, c=>d , b=>16'::hstore->'gg') is null; |
| 73 |
select ('aa=>NULL, c=>d , b=>16'::hstore->'aa') is null; |
| 74 |
select ('aa=>"NULL", c=>d , b=>16'::hstore->'aa') is null; |
| 75 |
|
| 76 |
-- -> array operator |
| 77 |
|
| 78 |
select 'aa=>"NULL", c=>d , b=>16'::hstore -> ARRAY['aa','c']; |
| 79 |
select 'aa=>"NULL", c=>d , b=>16'::hstore -> ARRAY['c','aa']; |
| 80 |
select 'aa=>NULL, c=>d , b=>16'::hstore -> ARRAY['aa','c',null]; |
| 81 |
select 'aa=>1, c=>3, b=>2, d=>4'::hstore -> ARRAY[['b','d'],['aa','c']]; |
| 82 |
|
| 83 |
-- exists/defined |
| 84 |
|
| 85 |
select exist('a=>NULL, b=>qq', 'a'); |
| 86 |
select exist('a=>NULL, b=>qq', 'b'); |
| 87 |
select exist('a=>NULL, b=>qq', 'c'); |
| 88 |
select exist('a=>"NULL", b=>qq', 'a'); |
| 89 |
select defined('a=>NULL, b=>qq', 'a'); |
| 90 |
select defined('a=>NULL, b=>qq', 'b'); |
| 91 |
select defined('a=>NULL, b=>qq', 'c'); |
| 92 |
select defined('a=>"NULL", b=>qq', 'a'); |
| 93 |
select hstore 'a=>NULL, b=>qq' ? 'a'; |
| 94 |
select hstore 'a=>NULL, b=>qq' ? 'b'; |
| 95 |
select hstore 'a=>NULL, b=>qq' ? 'c'; |
| 96 |
select hstore 'a=>"NULL", b=>qq' ? 'a'; |
| 97 |
select hstore 'a=>NULL, b=>qq' ?| ARRAY['a','b']; |
| 98 |
select hstore 'a=>NULL, b=>qq' ?| ARRAY['b','a']; |
| 99 |
select hstore 'a=>NULL, b=>qq' ?| ARRAY['c','a']; |
| 100 |
select hstore 'a=>NULL, b=>qq' ?| ARRAY['c','d']; |
| 101 |
select hstore 'a=>NULL, b=>qq' ?| '{}'::text[]; |
| 102 |
select hstore 'a=>NULL, b=>qq' ?& ARRAY['a','b']; |
| 103 |
select hstore 'a=>NULL, b=>qq' ?& ARRAY['b','a']; |
| 104 |
select hstore 'a=>NULL, b=>qq' ?& ARRAY['c','a']; |
| 105 |
select hstore 'a=>NULL, b=>qq' ?& ARRAY['c','d']; |
| 106 |
select hstore 'a=>NULL, b=>qq' ?& '{}'::text[]; |
| 107 |
|
| 108 |
-- delete |
| 109 |
|
| 110 |
select delete('a=>1 , b=>2, c=>3'::hstore, 'a'); |
| 111 |
select delete('a=>null , b=>2, c=>3'::hstore, 'a'); |
| 112 |
select delete('a=>1 , b=>2, c=>3'::hstore, 'b'); |
| 113 |
select delete('a=>1 , b=>2, c=>3'::hstore, 'c'); |
| 114 |
select delete('a=>1 , b=>2, c=>3'::hstore, 'd'); |
| 115 |
select 'a=>1 , b=>2, c=>3'::hstore - 'a'::text; |
| 116 |
select 'a=>null , b=>2, c=>3'::hstore - 'a'::text; |
| 117 |
select 'a=>1 , b=>2, c=>3'::hstore - 'b'::text; |
| 118 |
select 'a=>1 , b=>2, c=>3'::hstore - 'c'::text; |
| 119 |
select 'a=>1 , b=>2, c=>3'::hstore - 'd'::text; |
| 120 |
select pg_column_size('a=>1 , b=>2, c=>3'::hstore - 'b'::text) |
| 121 |
= pg_column_size('a=>1, b=>2'::hstore); |
| 122 |
|
| 123 |
-- delete (array) |
| 124 |
|
| 125 |
select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['d','e']); |
| 126 |
select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['d','b']); |
| 127 |
select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['a','c']); |
| 128 |
select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY[['b'],['c'],['a']]); |
| 129 |
select delete('a=>1 , b=>2, c=>3'::hstore, '{}'::text[]); |
| 130 |
select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['d','e']; |
| 131 |
select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['d','b']; |
| 132 |
select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['a','c']; |
| 133 |
select 'a=>1 , b=>2, c=>3'::hstore - ARRAY[['b'],['c'],['a']]; |
| 134 |
select 'a=>1 , b=>2, c=>3'::hstore - '{}'::text[]; |
| 135 |
select pg_column_size('a=>1 , b=>2, c=>3'::hstore - ARRAY['a','c']) |
| 136 |
= pg_column_size('b=>2'::hstore); |
| 137 |
select pg_column_size('a=>1 , b=>2, c=>3'::hstore - '{}'::text[]) |
| 138 |
= pg_column_size('a=>1, b=>2, c=>3'::hstore); |
| 139 |
|
| 140 |
-- delete (hstore) |
| 141 |
|
| 142 |
select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>4, b=>2'::hstore); |
| 143 |
select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>NULL, c=>3'::hstore); |
| 144 |
select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>1, b=>2, c=>3'::hstore); |
| 145 |
select delete('aa=>1 , b=>2, c=>3'::hstore, 'b=>2'::hstore); |
| 146 |
select delete('aa=>1 , b=>2, c=>3'::hstore, ''::hstore); |
| 147 |
select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>4, b=>2'::hstore; |
| 148 |
select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>NULL, c=>3'::hstore; |
| 149 |
select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>1, b=>2, c=>3'::hstore; |
| 150 |
select 'aa=>1 , b=>2, c=>3'::hstore - 'b=>2'::hstore; |
| 151 |
select 'aa=>1 , b=>2, c=>3'::hstore - ''::hstore; |
| 152 |
select pg_column_size('a=>1 , b=>2, c=>3'::hstore - 'b=>2'::hstore) |
| 153 |
= pg_column_size('a=>1, c=>3'::hstore); |
| 154 |
select pg_column_size('a=>1 , b=>2, c=>3'::hstore - ''::hstore) |
| 155 |
= pg_column_size('a=>1, b=>2, c=>3'::hstore); |
| 156 |
|
| 157 |
-- || |
| 158 |
select 'aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f'; |
| 159 |
select 'aa=>1 , b=>2, cq=>3'::hstore || 'aq=>l'; |
| 160 |
select 'aa=>1 , b=>2, cq=>3'::hstore || 'aa=>l'; |
| 161 |
select 'aa=>1 , b=>2, cq=>3'::hstore || ''; |
| 162 |
select ''::hstore || 'cq=>l, b=>g, fg=>f'; |
| 163 |
select pg_column_size(''::hstore || ''::hstore) = pg_column_size(''::hstore); |
| 164 |
select pg_column_size('aa=>1'::hstore || 'b=>2'::hstore) |
| 165 |
= pg_column_size('aa=>1, b=>2'::hstore); |
| 166 |
select pg_column_size('aa=>1, b=>2'::hstore || ''::hstore) |
| 167 |
= pg_column_size('aa=>1, b=>2'::hstore); |
| 168 |
select pg_column_size(''::hstore || 'aa=>1, b=>2'::hstore) |
| 169 |
= pg_column_size('aa=>1, b=>2'::hstore); |
| 170 |
|
| 171 |
-- hstore(text,text) |
| 172 |
select 'a=>g, b=>c'::hstore || hstore('asd', 'gf'); |
| 173 |
select 'a=>g, b=>c'::hstore || hstore('b', 'gf'); |
| 174 |
select 'a=>g, b=>c'::hstore || hstore('b', 'NULL'); |
| 175 |
select 'a=>g, b=>c'::hstore || hstore('b', NULL); |
| 176 |
select ('a=>g, b=>c'::hstore || hstore(NULL, 'b')) is null; |
| 177 |
select pg_column_size(hstore('b', 'gf')) |
| 178 |
= pg_column_size('b=>gf'::hstore); |
| 179 |
select pg_column_size('a=>g, b=>c'::hstore || hstore('b', 'gf')) |
| 180 |
= pg_column_size('a=>g, b=>gf'::hstore); |
| 181 |
|
| 182 |
-- slice() |
| 183 |
select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['g','h','i']); |
| 184 |
select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b']); |
| 185 |
select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['aa','b']); |
| 186 |
select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b','aa']); |
| 187 |
select pg_column_size(slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b'])) |
| 188 |
= pg_column_size('b=>2, c=>3'::hstore); |
| 189 |
select pg_column_size(slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b','aa'])) |
| 190 |
= pg_column_size('aa=>1, b=>2, c=>3'::hstore); |
| 191 |
|
| 192 |
-- array input |
| 193 |
select '{}'::text[]::hstore; |
| 194 |
select ARRAY['a','g','b','h','asd']::hstore; |
| 195 |
select ARRAY['a','g','b','h','asd','i']::hstore; |
| 196 |
select ARRAY[['a','g'],['b','h'],['asd','i']]::hstore; |
| 197 |
select ARRAY[['a','g','b'],['h','asd','i']]::hstore; |
| 198 |
select ARRAY[[['a','g'],['b','h'],['asd','i']]]::hstore; |
| 199 |
select hstore('{}'::text[]); |
| 200 |
select hstore(ARRAY['a','g','b','h','asd']); |
| 201 |
select hstore(ARRAY['a','g','b','h','asd','i']); |
| 202 |
select hstore(ARRAY[['a','g'],['b','h'],['asd','i']]); |
| 203 |
select hstore(ARRAY[['a','g','b'],['h','asd','i']]); |
| 204 |
select hstore(ARRAY[[['a','g'],['b','h'],['asd','i']]]); |
| 205 |
select hstore('[0:5]={a,g,b,h,asd,i}'::text[]); |
| 206 |
select hstore('[0:2][1:2]={{a,g},{b,h},{asd,i}}'::text[]); |
| 207 |
|
| 208 |
-- pairs of arrays |
| 209 |
select hstore(ARRAY['a','b','asd'], ARRAY['g','h','i']); |
| 210 |
select hstore(ARRAY['a','b','asd'], ARRAY['g','h',NULL]); |
| 211 |
select hstore(ARRAY['z','y','x'], ARRAY['1','2','3']); |
| 212 |
select hstore(ARRAY['aaa','bb','c','d'], ARRAY[null::text,null,null,null]); |
| 213 |
select hstore(ARRAY['aaa','bb','c','d'], null); |
| 214 |
select quote_literal(hstore('{}'::text[], '{}'::text[])); |
| 215 |
select quote_literal(hstore('{}'::text[], null)); |
| 216 |
select hstore(ARRAY['a'], '{}'::text[]); -- error |
| 217 |
select hstore('{}'::text[], ARRAY['a']); -- error |
| 218 |
select pg_column_size(hstore(ARRAY['a','b','asd'], ARRAY['g','h','i'])) |
| 219 |
= pg_column_size('a=>g, b=>h, asd=>i'::hstore); |
| 220 |
|
| 221 |
-- records |
| 222 |
select hstore(v) from (values (1, 'foo', 1.2, 3::float8)) v(a,b,c,d); |
| 223 |
create domain hstestdom1 as integer not null default 0; |
| 224 |
create table testhstore0 (a integer, b text, c numeric, d float8); |
| 225 |
create table testhstore1 (a integer, b text, c numeric, d float8, e hstestdom1); |
| 226 |
insert into testhstore0 values (1, 'foo', 1.2, 3::float8); |
| 227 |
insert into testhstore1 values (1, 'foo', 1.2, 3::float8); |
| 228 |
select hstore(v) from testhstore1 v; |
| 229 |
select hstore(null::testhstore0); |
| 230 |
select hstore(null::testhstore1); |
| 231 |
select pg_column_size(hstore(v)) |
| 232 |
= pg_column_size('a=>1, b=>"foo", c=>"1.2", d=>"3", e=>"0"'::hstore) |
| 233 |
from testhstore1 v; |
| 234 |
select populate_record(v, hstore('c', '3.45')) from testhstore1 v; |
| 235 |
select populate_record(v, hstore('d', '3.45')) from testhstore1 v; |
| 236 |
select populate_record(v, hstore('e', '123')) from testhstore1 v; |
| 237 |
select populate_record(v, hstore('e', null)) from testhstore1 v; |
| 238 |
select populate_record(v, hstore('c', null)) from testhstore1 v; |
| 239 |
select populate_record(v, hstore('b', 'foo') || hstore('a', '123')) from testhstore1 v; |
| 240 |
select populate_record(v, hstore('b', 'foo') || hstore('e', null)) from testhstore0 v; |
| 241 |
select populate_record(v, hstore('b', 'foo') || hstore('e', null)) from testhstore1 v; |
| 242 |
select populate_record(v, '') from testhstore0 v; |
| 243 |
select populate_record(v, '') from testhstore1 v; |
| 244 |
select populate_record(null::testhstore1, hstore('c', '3.45') || hstore('a', '123')); |
| 245 |
select populate_record(null::testhstore1, hstore('c', '3.45') || hstore('e', '123')); |
| 246 |
select populate_record(null::testhstore0, ''); |
| 247 |
select populate_record(null::testhstore1, ''); |
| 248 |
select v #= hstore('c', '3.45') from testhstore1 v; |
| 249 |
select v #= hstore('d', '3.45') from testhstore1 v; |
| 250 |
select v #= hstore('e', '123') from testhstore1 v; |
| 251 |
select v #= hstore('c', null) from testhstore1 v; |
| 252 |
select v #= hstore('e', null) from testhstore0 v; |
| 253 |
select v #= hstore('e', null) from testhstore1 v; |
| 254 |
select v #= (hstore('b', 'foo') || hstore('a', '123')) from testhstore1 v; |
| 255 |
select v #= (hstore('b', 'foo') || hstore('e', '123')) from testhstore1 v; |
| 256 |
select v #= hstore '' from testhstore0 v; |
| 257 |
select v #= hstore '' from testhstore1 v; |
| 258 |
select null::testhstore1 #= (hstore('c', '3.45') || hstore('a', '123')); |
| 259 |
select null::testhstore1 #= (hstore('c', '3.45') || hstore('e', '123')); |
| 260 |
select null::testhstore0 #= hstore ''; |
| 261 |
select null::testhstore1 #= hstore ''; |
| 262 |
select v #= h from testhstore1 v, (values (hstore 'a=>123',1),('b=>foo,c=>3.21',2),('a=>null',3),('e=>123',4),('f=>blah',5)) x(h,i) order by i; |
| 263 |
|
| 264 |
-- keys/values |
| 265 |
select akeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f'); |
| 266 |
select akeys('""=>1'); |
| 267 |
select akeys(''); |
| 268 |
select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f'); |
| 269 |
select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL'); |
| 270 |
select avals('""=>1'); |
| 271 |
select avals(''); |
| 272 |
|
| 273 |
select hstore_to_array('aa=>1, cq=>l, b=>g, fg=>NULL'::hstore); |
| 274 |
select %% 'aa=>1, cq=>l, b=>g, fg=>NULL'; |
| 275 |
|
| 276 |
select hstore_to_matrix('aa=>1, cq=>l, b=>g, fg=>NULL'::hstore); |
| 277 |
select %# 'aa=>1, cq=>l, b=>g, fg=>NULL'; |
| 278 |
|
| 279 |
select * from skeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f'); |
| 280 |
select * from skeys('""=>1'); |
| 281 |
select * from skeys(''); |
| 282 |
select * from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f'); |
| 283 |
select *, svals is null from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL'); |
| 284 |
select * from svals('""=>1'); |
| 285 |
select * from svals(''); |
| 286 |
|
| 287 |
select * from each('aaa=>bq, b=>NULL, ""=>1 '); |
| 288 |
|
| 289 |
-- @> |
| 290 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b'; |
| 291 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL'; |
| 292 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, g=>NULL'; |
| 293 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL'; |
| 294 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c'; |
| 295 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b'; |
| 296 |
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q'; |
| 297 |
|
| 298 |
CREATE TABLE testhstore (h hstore); |
| 299 |
\copy testhstore from 'data/hstore.data' |
| 300 |
|
| 301 |
select count(*) from testhstore where h @> 'wait=>NULL'; |
| 302 |
select count(*) from testhstore where h @> 'wait=>CC'; |
| 303 |
select count(*) from testhstore where h @> 'wait=>CC, public=>t'; |
| 304 |
select count(*) from testhstore where h ? 'public'; |
| 305 |
select count(*) from testhstore where h ?| ARRAY['public','disabled']; |
| 306 |
select count(*) from testhstore where h ?& ARRAY['public','disabled']; |
| 307 |
|
| 308 |
create index hidx on testhstore using gist(h); |
| 309 |
set enable_seqscan=off; |
| 310 |
|
| 311 |
select count(*) from testhstore where h @> 'wait=>NULL'; |
| 312 |
select count(*) from testhstore where h @> 'wait=>CC'; |
| 313 |
select count(*) from testhstore where h @> 'wait=>CC, public=>t'; |
| 314 |
select count(*) from testhstore where h ? 'public'; |
| 315 |
select count(*) from testhstore where h ?| ARRAY['public','disabled']; |
| 316 |
select count(*) from testhstore where h ?& ARRAY['public','disabled']; |
| 317 |
|
| 318 |
drop index hidx; |
| 319 |
create index hidx on testhstore using gist(h gist_hstore_ops(siglen=0)); |
| 320 |
create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2025)); |
| 321 |
create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2024)); |
| 322 |
set enable_seqscan=off; |
| 323 |
|
| 324 |
select count(*) from testhstore where h @> 'wait=>NULL'; |
| 325 |
select count(*) from testhstore where h @> 'wait=>CC'; |
| 326 |
select count(*) from testhstore where h @> 'wait=>CC, public=>t'; |
| 327 |
select count(*) from testhstore where h ? 'public'; |
| 328 |
select count(*) from testhstore where h ?| ARRAY['public','disabled']; |
| 329 |
select count(*) from testhstore where h ?& ARRAY['public','disabled']; |
| 330 |
|
| 331 |
drop index hidx; |
| 332 |
create index hidx on testhstore using gin (h); |
| 333 |
set enable_seqscan=off; |
| 334 |
|
| 335 |
select count(*) from testhstore where h @> 'wait=>NULL'; |
| 336 |
select count(*) from testhstore where h @> 'wait=>CC'; |
| 337 |
select count(*) from testhstore where h @> 'wait=>CC, public=>t'; |
| 338 |
select count(*) from testhstore where h ? 'public'; |
| 339 |
select count(*) from testhstore where h ?| ARRAY['public','disabled']; |
| 340 |
select count(*) from testhstore where h ?& ARRAY['public','disabled']; |
| 341 |
|
| 342 |
select count(*) from (select (each(h)).key from testhstore) as wow ; |
| 343 |
select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key; |
| 344 |
|
| 345 |
-- sort/hash |
| 346 |
select count(distinct h) from testhstore; |
| 347 |
set enable_hashagg = false; |
| 348 |
select count(*) from (select h from (select * from testhstore union all select * from testhstore) hs group by h) hs2; |
| 349 |
set enable_hashagg = true; |
| 350 |
set enable_sort = false; |
| 351 |
select count(*) from (select h from (select * from testhstore union all select * from testhstore) hs group by h) hs2; |
| 352 |
select distinct * from (values (hstore '' || ''),('')) v(h); |
| 353 |
set enable_sort = true; |
| 354 |
|
| 355 |
-- btree |
| 356 |
drop index hidx; |
| 357 |
create index hidx on testhstore using btree (h); |
| 358 |
set enable_seqscan=off; |
| 359 |
|
| 360 |
select count(*) from testhstore where h #># 'p=>1'; |
| 361 |
select count(*) from testhstore where h = 'pos=>98, line=>371, node=>CBA, indexed=>t'; |
| 362 |
|
| 363 |
-- json and jsonb |
| 364 |
select hstore_to_json('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4'); |
| 365 |
select cast( hstore '"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4' as json); |
| 366 |
select hstore_to_json_loose('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4, h=> "2016-01-01"'); |
| 367 |
|
| 368 |
select hstore_to_jsonb('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4'); |
| 369 |
select cast( hstore '"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4' as jsonb); |
| 370 |
select hstore_to_jsonb_loose('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4, h=> "2016-01-01"'); |
| 371 |
|
| 372 |
create table test_json_agg (f1 text, f2 hstore); |
| 373 |
insert into test_json_agg values ('rec1','"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4'), |
| 374 |
('rec2','"a key" =>2, b => f, c => "null", d=> -12345, e => 012345.6, f=> -1.234, g=> 0.345e-4'); |
| 375 |
select json_agg(q) from test_json_agg q; |
| 376 |
select json_agg(q) from (select f1, hstore_to_json_loose(f2) as f2 from test_json_agg) q; |
| 377 |
|
| 378 |
-- Test subscripting |
| 379 |
insert into test_json_agg default values; |
| 380 |
select f2['d'], f2['x'] is null as x_isnull from test_json_agg; |
| 381 |
select f2['d']['e'] from test_json_agg; -- error |
| 382 |
select f2['d':'e'] from test_json_agg; -- error |
| 383 |
update test_json_agg set f2['d'] = f2['e'], f2['x'] = 'xyzzy'; |
| 384 |
select f2 from test_json_agg; |
| 385 |
|
| 386 |
-- Test subscripting in plpgsql |
| 387 |
do $$ declare h hstore; |
| 388 |
begin h['a'] := 'b'; raise notice 'h = %, h[a] = %', h, h['a']; end $$; |
| 389 |
|
| 390 |
-- Check the hstore_hash() and hstore_hash_extended() function explicitly. |
| 391 |
SELECT v as value, hstore_hash(v)::bit(32) as standard, |
| 392 |
hstore_hash_extended(v, 0)::bit(32) as extended0, |
| 393 |
hstore_hash_extended(v, 1)::bit(32) as extended1 |
| 394 |
FROM (VALUES (NULL::hstore), (''), ('"a key" =>1'), ('c => null'), |
| 395 |
('e => 012345'), ('g => 2.345e+4')) x(v) |
| 396 |
WHERE hstore_hash(v)::bit(32) != hstore_hash_extended(v, 0)::bit(32) |
| 397 |
OR hstore_hash(v)::bit(32) = hstore_hash_extended(v, 1)::bit(32); |