hstore.out 10.3 KB
Newer Older
1 2 3 4 5
--
-- first, define the datatype.  Turn off echoing so that expected file
-- does not depend on contents of hstore.sql.
--
SET client_min_messages = warning;
T
Teodor Sigaev 已提交
6
\set ECHO none
7 8
RESET client_min_messages;
set escape_string_warning=off;
T
Teodor Sigaev 已提交
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207
--hstore;
select ''::hstore;
 hstore 
--------
 
(1 row)

select 'a=>b'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select ' a=>b'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select 'a =>b'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select 'a=>b '::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select 'a=> b'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select '"a"=>"b"'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select ' "a"=>"b"'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select '"a" =>"b"'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select '"a"=>"b" '::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select '"a"=> "b"'::hstore;
  hstore  
----------
 "a"=>"b"
(1 row)

select 'aa=>bb'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select ' aa=>bb'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select 'aa =>bb'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select 'aa=>bb '::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select 'aa=> bb'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select '"aa"=>"bb"'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select ' "aa"=>"bb"'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select '"aa" =>"bb"'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select '"aa"=>"bb" '::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select '"aa"=> "bb"'::hstore;
   hstore   
------------
 "aa"=>"bb"
(1 row)

select 'aa=>bb, cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>bb , cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>bb ,cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>bb, "cc"=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>bb , "cc"=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>bb ,"cc"=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>"bb", cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>"bb" , cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>"bb" ,cc=>dd'::hstore;
         hstore         
------------------------
 "aa"=>"bb", "cc"=>"dd"
(1 row)

select 'aa=>null'::hstore;
   hstore   
------------
 "aa"=>NULL
(1 row)

select 'aa=>NuLl'::hstore;
   hstore   
------------
 "aa"=>NULL
(1 row)

select 'aa=>"NuLl"'::hstore;
    hstore    
--------------
 "aa"=>"NuLl"
(1 row)

208
select e'\\=a=>q=w'::hstore;
T
Teodor Sigaev 已提交
209 210 211 212 213
   hstore    
-------------
 "=a"=>"q=w"
(1 row)

214
select e'"=a"=>q\\=w'::hstore;
T
Teodor Sigaev 已提交
215 216 217 218 219
   hstore    
-------------
 "=a"=>"q=w"
(1 row)

220
select e'"\\"a"=>q>w'::hstore;
T
Teodor Sigaev 已提交
221 222 223 224 225
    hstore    
--------------
 "\"a"=>"q>w"
(1 row)

226
select e'\\"a=>q"w'::hstore;
T
Teodor Sigaev 已提交
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
    hstore     
---------------
 "\"a"=>"q\"w"
(1 row)

select ''::hstore;
 hstore 
--------
 
(1 row)

select '	'::hstore;
 hstore 
--------
 
(1 row)

-- -> operator
select 'aa=>b, c=>d , b=>16'::hstore->'c';
 ?column? 
----------
 d
(1 row)

select 'aa=>b, c=>d , b=>16'::hstore->'b';
 ?column? 
----------
 16
(1 row)

select 'aa=>b, c=>d , b=>16'::hstore->'aa';
 ?column? 
----------
 b
(1 row)

select ('aa=>b, c=>d , b=>16'::hstore->'gg') is null;
 ?column? 
----------
 t
(1 row)

select ('aa=>NULL, c=>d , b=>16'::hstore->'aa') is null;
 ?column? 
----------
 t
(1 row)

275 276 277 278 279 280
select ('aa=>"NULL", c=>d , b=>16'::hstore->'aa') is null;
 ?column? 
----------
 f
(1 row)

T
Teodor Sigaev 已提交
281
-- exists/defined
282 283 284
select exist('a=>NULL, b=>qq', 'a');
 exist 
-------
T
Teodor Sigaev 已提交
285 286 287
 t
(1 row)

288 289 290
select exist('a=>NULL, b=>qq', 'b');
 exist 
-------
T
Teodor Sigaev 已提交
291 292 293
 t
(1 row)

294 295 296
select exist('a=>NULL, b=>qq', 'c');
 exist 
-------
T
Teodor Sigaev 已提交
297 298 299
 f
(1 row)

300 301 302 303 304 305
select exist('a=>"NULL", b=>qq', 'a');
 exist 
-------
 t
(1 row)

306 307 308
select defined('a=>NULL, b=>qq', 'a');
 defined 
---------
T
Teodor Sigaev 已提交
309 310 311
 f
(1 row)

312 313 314
select defined('a=>NULL, b=>qq', 'b');
 defined 
---------
T
Teodor Sigaev 已提交
315 316 317
 t
(1 row)

318 319 320
select defined('a=>NULL, b=>qq', 'c');
 defined 
---------
T
Teodor Sigaev 已提交
321 322 323
 f
(1 row)

324 325 326 327 328 329
select defined('a=>"NULL", b=>qq', 'a');
 defined 
---------
 t
(1 row)

T
Teodor Sigaev 已提交
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
-- delete 
select delete('a=>1 , b=>2, c=>3'::hstore, 'a');
       delete       
--------------------
 "b"=>"2", "c"=>"3"
(1 row)

select delete('a=>null , b=>2, c=>3'::hstore, 'a');
       delete       
--------------------
 "b"=>"2", "c"=>"3"
(1 row)

select delete('a=>1 , b=>2, c=>3'::hstore, 'b');
       delete       
--------------------
 "a"=>"1", "c"=>"3"
(1 row)

select delete('a=>1 , b=>2, c=>3'::hstore, 'c');
       delete       
--------------------
 "a"=>"1", "b"=>"2"
(1 row)

select delete('a=>1 , b=>2, c=>3'::hstore, 'd');
            delete            
------------------------------
 "a"=>"1", "b"=>"2", "c"=>"3"
(1 row)

-- ||
select 'aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f';
                 ?column?                  
-------------------------------------------
 "b"=>"g", "aa"=>"1", "cq"=>"l", "fg"=>"f"
(1 row)

select 'aa=>1 , b=>2, cq=>3'::hstore || 'aq=>l';
                 ?column?                  
-------------------------------------------
 "b"=>"2", "aa"=>"1", "aq"=>"l", "cq"=>"3"
(1 row)

select 'aa=>1 , b=>2, cq=>3'::hstore || 'aa=>l';
            ?column?            
--------------------------------
 "b"=>"2", "aa"=>"l", "cq"=>"3"
(1 row)

select 'aa=>1 , b=>2, cq=>3'::hstore || '';
            ?column?            
--------------------------------
 "b"=>"2", "aa"=>"1", "cq"=>"3"
(1 row)

select ''::hstore || 'cq=>l, b=>g, fg=>f';
            ?column?            
--------------------------------
 "b"=>"g", "cq"=>"l", "fg"=>"f"
(1 row)

-- =>
select 'a=>g, b=>c'::hstore || ( 'asd'=>'gf' );
            ?column?             
---------------------------------
 "a"=>"g", "b"=>"c", "asd"=>"gf"
(1 row)

select 'a=>g, b=>c'::hstore || ( 'b'=>'gf' );
      ?column?       
---------------------
 "a"=>"g", "b"=>"gf"
(1 row)

405 406 407 408 409 410 411 412 413 414 415 416
select 'a=>g, b=>c'::hstore || ( 'b'=>'NULL' );
       ?column?        
-----------------------
 "a"=>"g", "b"=>"NULL"
(1 row)

select 'a=>g, b=>c'::hstore || ( 'b'=>NULL );
      ?column?       
---------------------
 "a"=>"g", "b"=>NULL
(1 row)

T
Teodor Sigaev 已提交
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
-- keys/values
select akeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
    akeys     
--------------
 {b,aa,cq,fg}
(1 row)

select akeys('""=>1');
 akeys 
-------
 {""}
(1 row)

select akeys('');
 akeys 
-------
 {}
(1 row)

select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
   avals   
-----------
 {g,1,l,f}
(1 row)

select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
   avals    
------------
 {g,1,l,""}
(1 row)

select avals('""=>1');
 avals 
-------
 {1}
(1 row)

select avals('');
 avals 
-------
 {}
(1 row)

select * from skeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
 skeys 
-------
 b
 aa
 cq
 fg
(4 rows)

select * from skeys('""=>1');
 skeys 
-------
 
(1 row)

select * from skeys('');
 skeys 
-------
(0 rows)

select * from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
 svals 
-------
 g
 1
 l
 f
(4 rows)

select *, svals is null from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
 svals | ?column? 
-------+----------
 g     | f
 1     | f
 l     | f
       | t
(4 rows)

select * from svals('""=>1');
 svals 
-------
 1
(1 row)

select * from svals('');
 svals 
-------
(0 rows)

select * from each('aaa=>bq, b=>NULL, ""=>1 ');
 key | value 
-----+-------
     | 1
 b   | 
 aaa | bq
(3 rows)

517
-- @>
518
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
T
Teodor Sigaev 已提交
519 520 521 522 523
 ?column? 
----------
 t
(1 row)

524
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
T
Teodor Sigaev 已提交
525 526 527 528 529
 ?column? 
----------
 t
(1 row)

530
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, g=>NULL';
T
Teodor Sigaev 已提交
531 532 533 534 535
 ?column? 
----------
 f
(1 row)

536
select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
T
Teodor Sigaev 已提交
537 538 539 540 541
 ?column? 
----------
 f
(1 row)

542
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
T
Teodor Sigaev 已提交
543 544 545 546 547
 ?column? 
----------
 f
(1 row)

548
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
T
Teodor Sigaev 已提交
549 550 551 552 553
 ?column? 
----------
 t
(1 row)

554
select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
T
Teodor Sigaev 已提交
555 556 557 558 559 560
 ?column? 
----------
 f
(1 row)

CREATE TABLE testhstore (h hstore);
561
NOTICE:  Table doesn't have 'DISTRIBUTED BY' clause, and no column type is suitable for a distribution key. Creating a NULL policy entry.
T
Teodor Sigaev 已提交
562
\copy testhstore from 'data/hstore.data'
563
select count(*) from testhstore where h @> 'wait=>NULL';
T
Teodor Sigaev 已提交
564 565
 count 
-------
566
     1
T
Teodor Sigaev 已提交
567 568
(1 row)

569
select count(*) from testhstore where h @> 'wait=>CC';
T
Teodor Sigaev 已提交
570 571 572 573 574
 count 
-------
    15
(1 row)

575
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
T
Teodor Sigaev 已提交
576 577 578 579 580
 count 
-------
     2
(1 row)

581 582 583 584 585 586
select count(*) from testhstore where h ? 'public';
 count 
-------
   194
(1 row)

T
Teodor Sigaev 已提交
587 588
create index hidx on testhstore using gist(h);
set enable_seqscan=off;
589
select count(*) from testhstore where h @> 'wait=>NULL';
T
Teodor Sigaev 已提交
590 591
 count 
-------
592
     1
T
Teodor Sigaev 已提交
593 594
(1 row)

595
select count(*) from testhstore where h @> 'wait=>CC';
T
Teodor Sigaev 已提交
596 597 598 599 600
 count 
-------
    15
(1 row)

601
select count(*) from testhstore where h @> 'wait=>CC, public=>t';
T
Teodor Sigaev 已提交
602 603 604 605 606
 count 
-------
     2
(1 row)

607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
select count(*) from testhstore where h ? 'public';
 count 
-------
   194
(1 row)

drop index hidx;
create index hidx on testhstore using gin (h);
set enable_seqscan=off;
select count(*) from testhstore where h @> 'wait=>NULL';
 count 
-------
     1
(1 row)

select count(*) from testhstore where h @> 'wait=>CC';
 count 
-------
    15
(1 row)

select count(*) from testhstore where h @> 'wait=>CC, public=>t';
 count 
-------
     2
(1 row)

select count(*) from testhstore where h ? 'public';
 count 
-------
   194
(1 row)

T
Teodor Sigaev 已提交
640 641 642
select count(*) from (select (each(h)).key from testhstore) as wow ;
 count 
-------
643
  4781
T
Teodor Sigaev 已提交
644 645 646 647 648
(1 row)

select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key;
    key    | count 
-----------+-------
649
 line      |   884
T
Teodor Sigaev 已提交
650 651 652 653 654 655 656
 query     |   207
 pos       |   203
 node      |   202
 space     |   197
 status    |   195
 public    |   194
 title     |   190
657
 wait      |   190
T
Teodor Sigaev 已提交
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672
 org       |   189
 user      |   189
 coauthors |   188
 disabled  |   185
 indexed   |   184
 cleaned   |   180
 bad       |   179
 date      |   179
 world     |   176
 state     |   172
 subtitle  |   169
 auth      |   168
 abstract  |   161
(22 rows)