1 CREATE EXTENSION hstore;
2 -- Check whether any of our opclasses fail amvalidate
4 FROM pg_opclass opc LEFT JOIN pg_am am ON am.oid = opcmethod
5 WHERE opc.oid >= 16384 AND NOT amvalidate(opc.oid);
10 set escape_string_warning=off;
18 select 'a=>b'::hstore;
24 select ' a=>b'::hstore;
30 select 'a =>b'::hstore;
36 select 'a=>b '::hstore;
42 select 'a=> b'::hstore;
48 select '"a"=>"b"'::hstore;
54 select ' "a"=>"b"'::hstore;
60 select '"a" =>"b"'::hstore;
66 select '"a"=>"b" '::hstore;
72 select '"a"=> "b"'::hstore;
78 select 'aa=>bb'::hstore;
84 select ' aa=>bb'::hstore;
90 select 'aa =>bb'::hstore;
96 select 'aa=>bb '::hstore;
102 select 'aa=> bb'::hstore;
108 select '"aa"=>"bb"'::hstore;
114 select ' "aa"=>"bb"'::hstore;
120 select '"aa" =>"bb"'::hstore;
126 select '"aa"=>"bb" '::hstore;
132 select '"aa"=> "bb"'::hstore;
138 select 'aa=>bb, cc=>dd'::hstore;
140 ------------------------
141 "aa"=>"bb", "cc"=>"dd"
144 select 'aa=>bb , cc=>dd'::hstore;
146 ------------------------
147 "aa"=>"bb", "cc"=>"dd"
150 select 'aa=>bb ,cc=>dd'::hstore;
152 ------------------------
153 "aa"=>"bb", "cc"=>"dd"
156 select 'aa=>bb, "cc"=>dd'::hstore;
158 ------------------------
159 "aa"=>"bb", "cc"=>"dd"
162 select 'aa=>bb , "cc"=>dd'::hstore;
164 ------------------------
165 "aa"=>"bb", "cc"=>"dd"
168 select 'aa=>bb ,"cc"=>dd'::hstore;
170 ------------------------
171 "aa"=>"bb", "cc"=>"dd"
174 select 'aa=>"bb", cc=>dd'::hstore;
176 ------------------------
177 "aa"=>"bb", "cc"=>"dd"
180 select 'aa=>"bb" , cc=>dd'::hstore;
182 ------------------------
183 "aa"=>"bb", "cc"=>"dd"
186 select 'aa=>"bb" ,cc=>dd'::hstore;
188 ------------------------
189 "aa"=>"bb", "cc"=>"dd"
192 select 'aa=>null'::hstore;
198 select 'aa=>NuLl'::hstore;
204 select 'aa=>"NuLl"'::hstore;
210 select e'\\=a=>q=w'::hstore;
216 select e'"=a"=>q\\=w'::hstore;
222 select e'"\\"a"=>q>w'::hstore;
228 select e'\\"a=>q"w'::hstore;
247 select ' =>null'::hstore;
248 ERROR: syntax error in hstore, near "=" at position 2
249 LINE 1: select ' =>null'::hstore;
251 select 'aa=>"'::hstore;
252 ERROR: syntax error in hstore: unexpected end of string
253 LINE 1: select 'aa=>"'::hstore;
255 -- also try it with non-error-throwing API
256 select pg_input_is_valid('a=>b', 'hstore');
262 select pg_input_is_valid('a=b', 'hstore');
268 select * from pg_input_error_info('a=b', 'hstore');
269 message | detail | hint | sql_error_code
270 ------------------------------------------------+--------+------+----------------
271 syntax error in hstore, near "b" at position 2 | | | 42601
274 select * from pg_input_error_info(' =>b', 'hstore');
275 message | detail | hint | sql_error_code
276 ------------------------------------------------+--------+------+----------------
277 syntax error in hstore, near "=" at position 1 | | | 42601
281 select 'aa=>b, c=>d , b=>16'::hstore->'c';
287 select 'aa=>b, c=>d , b=>16'::hstore->'b';
293 select 'aa=>b, c=>d , b=>16'::hstore->'aa';
299 select ('aa=>b, c=>d , b=>16'::hstore->'gg') is null;
305 select ('aa=>NULL, c=>d , b=>16'::hstore->'aa') is null;
311 select ('aa=>"NULL", c=>d , b=>16'::hstore->'aa') is null;
318 select 'aa=>"NULL", c=>d , b=>16'::hstore -> ARRAY['aa','c'];
324 select 'aa=>"NULL", c=>d , b=>16'::hstore -> ARRAY['c','aa'];
330 select 'aa=>NULL, c=>d , b=>16'::hstore -> ARRAY['aa','c',null];
336 select 'aa=>1, c=>3, b=>2, d=>4'::hstore -> ARRAY[['b','d'],['aa','c']];
343 select exist('a=>NULL, b=>qq', 'a');
349 select exist('a=>NULL, b=>qq', 'b');
355 select exist('a=>NULL, b=>qq', 'c');
361 select exist('a=>"NULL", b=>qq', 'a');
367 select defined('a=>NULL, b=>qq', 'a');
373 select defined('a=>NULL, b=>qq', 'b');
379 select defined('a=>NULL, b=>qq', 'c');
385 select defined('a=>"NULL", b=>qq', 'a');
391 select hstore 'a=>NULL, b=>qq' ? 'a';
397 select hstore 'a=>NULL, b=>qq' ? 'b';
403 select hstore 'a=>NULL, b=>qq' ? 'c';
409 select hstore 'a=>"NULL", b=>qq' ? 'a';
415 select hstore 'a=>NULL, b=>qq' ?| ARRAY['a','b'];
421 select hstore 'a=>NULL, b=>qq' ?| ARRAY['b','a'];
427 select hstore 'a=>NULL, b=>qq' ?| ARRAY['c','a'];
433 select hstore 'a=>NULL, b=>qq' ?| ARRAY['c','d'];
439 select hstore 'a=>NULL, b=>qq' ?| '{}'::text[];
445 select hstore 'a=>NULL, b=>qq' ?& ARRAY['a','b'];
451 select hstore 'a=>NULL, b=>qq' ?& ARRAY['b','a'];
457 select hstore 'a=>NULL, b=>qq' ?& ARRAY['c','a'];
463 select hstore 'a=>NULL, b=>qq' ?& ARRAY['c','d'];
469 select hstore 'a=>NULL, b=>qq' ?& '{}'::text[];
476 select delete('a=>1 , b=>2, c=>3'::hstore, 'a');
482 select delete('a=>null , b=>2, c=>3'::hstore, 'a');
488 select delete('a=>1 , b=>2, c=>3'::hstore, 'b');
494 select delete('a=>1 , b=>2, c=>3'::hstore, 'c');
500 select delete('a=>1 , b=>2, c=>3'::hstore, 'd');
502 ------------------------------
503 "a"=>"1", "b"=>"2", "c"=>"3"
506 select 'a=>1 , b=>2, c=>3'::hstore - 'a'::text;
512 select 'a=>null , b=>2, c=>3'::hstore - 'a'::text;
518 select 'a=>1 , b=>2, c=>3'::hstore - 'b'::text;
524 select 'a=>1 , b=>2, c=>3'::hstore - 'c'::text;
530 select 'a=>1 , b=>2, c=>3'::hstore - 'd'::text;
532 ------------------------------
533 "a"=>"1", "b"=>"2", "c"=>"3"
536 select pg_column_size('a=>1 , b=>2, c=>3'::hstore - 'b'::text)
537 = pg_column_size('a=>1, b=>2'::hstore);
544 select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['d','e']);
546 ------------------------------
547 "a"=>"1", "b"=>"2", "c"=>"3"
550 select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['d','b']);
556 select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY['a','c']);
562 select delete('a=>1 , b=>2, c=>3'::hstore, ARRAY[['b'],['c'],['a']]);
568 select delete('a=>1 , b=>2, c=>3'::hstore, '{}'::text[]);
570 ------------------------------
571 "a"=>"1", "b"=>"2", "c"=>"3"
574 select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['d','e'];
576 ------------------------------
577 "a"=>"1", "b"=>"2", "c"=>"3"
580 select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['d','b'];
586 select 'a=>1 , b=>2, c=>3'::hstore - ARRAY['a','c'];
592 select 'a=>1 , b=>2, c=>3'::hstore - ARRAY[['b'],['c'],['a']];
598 select 'a=>1 , b=>2, c=>3'::hstore - '{}'::text[];
600 ------------------------------
601 "a"=>"1", "b"=>"2", "c"=>"3"
604 select pg_column_size('a=>1 , b=>2, c=>3'::hstore - ARRAY['a','c'])
605 = pg_column_size('b=>2'::hstore);
611 select pg_column_size('a=>1 , b=>2, c=>3'::hstore - '{}'::text[])
612 = pg_column_size('a=>1, b=>2, c=>3'::hstore);
619 select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>4, b=>2'::hstore);
621 ---------------------
625 select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>NULL, c=>3'::hstore);
627 ---------------------
631 select delete('aa=>1 , b=>2, c=>3'::hstore, 'aa=>1, b=>2, c=>3'::hstore);
637 select delete('aa=>1 , b=>2, c=>3'::hstore, 'b=>2'::hstore);
639 ---------------------
643 select delete('aa=>1 , b=>2, c=>3'::hstore, ''::hstore);
645 -------------------------------
646 "b"=>"2", "c"=>"3", "aa"=>"1"
649 select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>4, b=>2'::hstore;
651 ---------------------
655 select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>NULL, c=>3'::hstore;
657 ---------------------
661 select 'aa=>1 , b=>2, c=>3'::hstore - 'aa=>1, b=>2, c=>3'::hstore;
667 select 'aa=>1 , b=>2, c=>3'::hstore - 'b=>2'::hstore;
669 ---------------------
673 select 'aa=>1 , b=>2, c=>3'::hstore - ''::hstore;
675 -------------------------------
676 "b"=>"2", "c"=>"3", "aa"=>"1"
679 select pg_column_size('a=>1 , b=>2, c=>3'::hstore - 'b=>2'::hstore)
680 = pg_column_size('a=>1, c=>3'::hstore);
686 select pg_column_size('a=>1 , b=>2, c=>3'::hstore - ''::hstore)
687 = pg_column_size('a=>1, b=>2, c=>3'::hstore);
694 select 'aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f';
696 -------------------------------------------
697 "b"=>"g", "aa"=>"1", "cq"=>"l", "fg"=>"f"
700 select 'aa=>1 , b=>2, cq=>3'::hstore || 'aq=>l';
702 -------------------------------------------
703 "b"=>"2", "aa"=>"1", "aq"=>"l", "cq"=>"3"
706 select 'aa=>1 , b=>2, cq=>3'::hstore || 'aa=>l';
708 --------------------------------
709 "b"=>"2", "aa"=>"l", "cq"=>"3"
712 select 'aa=>1 , b=>2, cq=>3'::hstore || '';
714 --------------------------------
715 "b"=>"2", "aa"=>"1", "cq"=>"3"
718 select ''::hstore || 'cq=>l, b=>g, fg=>f';
720 --------------------------------
721 "b"=>"g", "cq"=>"l", "fg"=>"f"
724 select pg_column_size(''::hstore || ''::hstore) = pg_column_size(''::hstore);
730 select pg_column_size('aa=>1'::hstore || 'b=>2'::hstore)
731 = pg_column_size('aa=>1, b=>2'::hstore);
737 select pg_column_size('aa=>1, b=>2'::hstore || ''::hstore)
738 = pg_column_size('aa=>1, b=>2'::hstore);
744 select pg_column_size(''::hstore || 'aa=>1, b=>2'::hstore)
745 = pg_column_size('aa=>1, b=>2'::hstore);
752 select 'a=>g, b=>c'::hstore || hstore('asd', 'gf');
754 ---------------------------------
755 "a"=>"g", "b"=>"c", "asd"=>"gf"
758 select 'a=>g, b=>c'::hstore || hstore('b', 'gf');
760 ---------------------
764 select 'a=>g, b=>c'::hstore || hstore('b', 'NULL');
766 -----------------------
767 "a"=>"g", "b"=>"NULL"
770 select 'a=>g, b=>c'::hstore || hstore('b', NULL);
772 ---------------------
776 select ('a=>g, b=>c'::hstore || hstore(NULL, 'b')) is null;
782 select pg_column_size(hstore('b', 'gf'))
783 = pg_column_size('b=>gf'::hstore);
789 select pg_column_size('a=>g, b=>c'::hstore || hstore('b', 'gf'))
790 = pg_column_size('a=>g, b=>gf'::hstore);
797 select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['g','h','i']);
803 select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b']);
809 select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['aa','b']);
811 ---------------------
815 select slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b','aa']);
817 -------------------------------
818 "b"=>"2", "c"=>"3", "aa"=>"1"
821 select pg_column_size(slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b']))
822 = pg_column_size('b=>2, c=>3'::hstore);
828 select pg_column_size(slice(hstore 'aa=>1, b=>2, c=>3', ARRAY['c','b','aa']))
829 = pg_column_size('aa=>1, b=>2, c=>3'::hstore);
836 select '{}'::text[]::hstore;
842 select ARRAY['a','g','b','h','asd']::hstore;
843 ERROR: array must have even number of elements
844 select ARRAY['a','g','b','h','asd','i']::hstore;
846 --------------------------------
847 "a"=>"g", "b"=>"h", "asd"=>"i"
850 select ARRAY[['a','g'],['b','h'],['asd','i']]::hstore;
852 --------------------------------
853 "a"=>"g", "b"=>"h", "asd"=>"i"
856 select ARRAY[['a','g','b'],['h','asd','i']]::hstore;
857 ERROR: array must have two columns
858 select ARRAY[[['a','g'],['b','h'],['asd','i']]]::hstore;
859 ERROR: wrong number of array subscripts
860 select hstore('{}'::text[]);
866 select hstore(ARRAY['a','g','b','h','asd']);
867 ERROR: array must have even number of elements
868 select hstore(ARRAY['a','g','b','h','asd','i']);
870 --------------------------------
871 "a"=>"g", "b"=>"h", "asd"=>"i"
874 select hstore(ARRAY[['a','g'],['b','h'],['asd','i']]);
876 --------------------------------
877 "a"=>"g", "b"=>"h", "asd"=>"i"
880 select hstore(ARRAY[['a','g','b'],['h','asd','i']]);
881 ERROR: array must have two columns
882 select hstore(ARRAY[[['a','g'],['b','h'],['asd','i']]]);
883 ERROR: wrong number of array subscripts
884 select hstore('[0:5]={a,g,b,h,asd,i}'::text[]);
886 --------------------------------
887 "a"=>"g", "b"=>"h", "asd"=>"i"
890 select hstore('[0:2][1:2]={{a,g},{b,h},{asd,i}}'::text[]);
892 --------------------------------
893 "a"=>"g", "b"=>"h", "asd"=>"i"
897 select hstore(ARRAY['a','b','asd'], ARRAY['g','h','i']);
899 --------------------------------
900 "a"=>"g", "b"=>"h", "asd"=>"i"
903 select hstore(ARRAY['a','b','asd'], ARRAY['g','h',NULL]);
905 ---------------------------------
906 "a"=>"g", "b"=>"h", "asd"=>NULL
909 select hstore(ARRAY['z','y','x'], ARRAY['1','2','3']);
911 ------------------------------
912 "x"=>"3", "y"=>"2", "z"=>"1"
915 select hstore(ARRAY['aaa','bb','c','d'], ARRAY[null::text,null,null,null]);
917 -----------------------------------------------
918 "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL
921 select hstore(ARRAY['aaa','bb','c','d'], null);
923 -----------------------------------------------
924 "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL
927 select quote_literal(hstore('{}'::text[], '{}'::text[]));
933 select quote_literal(hstore('{}'::text[], null));
939 select hstore(ARRAY['a'], '{}'::text[]); -- error
940 ERROR: arrays must have same bounds
941 select hstore('{}'::text[], ARRAY['a']); -- error
942 ERROR: arrays must have same bounds
943 select pg_column_size(hstore(ARRAY['a','b','asd'], ARRAY['g','h','i']))
944 = pg_column_size('a=>g, b=>h, asd=>i'::hstore);
951 select hstore(v) from (values (1, 'foo', 1.2, 3::float8)) v(a,b,c,d);
953 --------------------------------------------
954 "a"=>"1", "b"=>"foo", "c"=>"1.2", "d"=>"3"
957 create domain hstestdom1 as integer not null default 0;
958 create table testhstore0 (a integer, b text, c numeric, d float8);
959 create table testhstore1 (a integer, b text, c numeric, d float8, e hstestdom1);
960 insert into testhstore0 values (1, 'foo', 1.2, 3::float8);
961 insert into testhstore1 values (1, 'foo', 1.2, 3::float8);
962 select hstore(v) from testhstore1 v;
964 ------------------------------------------------------
965 "a"=>"1", "b"=>"foo", "c"=>"1.2", "d"=>"3", "e"=>"0"
968 select hstore(null::testhstore0);
970 --------------------------------------------
971 "a"=>NULL, "b"=>NULL, "c"=>NULL, "d"=>NULL
974 select hstore(null::testhstore1);
976 -------------------------------------------------------
977 "a"=>NULL, "b"=>NULL, "c"=>NULL, "d"=>NULL, "e"=>NULL
980 select pg_column_size(hstore(v))
981 = pg_column_size('a=>1, b=>"foo", c=>"1.2", d=>"3", e=>"0"'::hstore)
988 select populate_record(v, hstore('c', '3.45')) from testhstore1 v;
994 select populate_record(v, hstore('d', '3.45')) from testhstore1 v;
1000 select populate_record(v, hstore('e', '123')) from testhstore1 v;
1006 select populate_record(v, hstore('e', null)) from testhstore1 v;
1007 ERROR: domain hstestdom1 does not allow null values
1008 select populate_record(v, hstore('c', null)) from testhstore1 v;
1014 select populate_record(v, hstore('b', 'foo') || hstore('a', '123')) from testhstore1 v;
1020 select populate_record(v, hstore('b', 'foo') || hstore('e', null)) from testhstore0 v;
1026 select populate_record(v, hstore('b', 'foo') || hstore('e', null)) from testhstore1 v;
1027 ERROR: domain hstestdom1 does not allow null values
1028 select populate_record(v, '') from testhstore0 v;
1034 select populate_record(v, '') from testhstore1 v;
1040 select populate_record(null::testhstore1, hstore('c', '3.45') || hstore('a', '123'));
1041 ERROR: domain hstestdom1 does not allow null values
1042 select populate_record(null::testhstore1, hstore('c', '3.45') || hstore('e', '123'));
1048 select populate_record(null::testhstore0, '');
1054 select populate_record(null::testhstore1, '');
1055 ERROR: domain hstestdom1 does not allow null values
1056 select v #= hstore('c', '3.45') from testhstore1 v;
1062 select v #= hstore('d', '3.45') from testhstore1 v;
1064 --------------------
1068 select v #= hstore('e', '123') from testhstore1 v;
1074 select v #= hstore('c', null) from testhstore1 v;
1080 select v #= hstore('e', null) from testhstore0 v;
1086 select v #= hstore('e', null) from testhstore1 v;
1087 ERROR: domain hstestdom1 does not allow null values
1088 select v #= (hstore('b', 'foo') || hstore('a', '123')) from testhstore1 v;
1094 select v #= (hstore('b', 'foo') || hstore('e', '123')) from testhstore1 v;
1100 select v #= hstore '' from testhstore0 v;
1106 select v #= hstore '' from testhstore1 v;
1112 select null::testhstore1 #= (hstore('c', '3.45') || hstore('a', '123'));
1113 ERROR: domain hstestdom1 does not allow null values
1114 select null::testhstore1 #= (hstore('c', '3.45') || hstore('e', '123'));
1120 select null::testhstore0 #= hstore '';
1126 select null::testhstore1 #= hstore '';
1127 ERROR: domain hstestdom1 does not allow null values
1128 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;
1139 select akeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
1145 select akeys('""=>1');
1157 select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
1163 select avals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
1169 select avals('""=>1');
1181 select hstore_to_array('aa=>1, cq=>l, b=>g, fg=>NULL'::hstore);
1183 -------------------------
1184 {b,g,aa,1,cq,l,fg,NULL}
1187 select %% 'aa=>1, cq=>l, b=>g, fg=>NULL';
1189 -------------------------
1190 {b,g,aa,1,cq,l,fg,NULL}
1193 select hstore_to_matrix('aa=>1, cq=>l, b=>g, fg=>NULL'::hstore);
1195 ---------------------------------
1196 {{b,g},{aa,1},{cq,l},{fg,NULL}}
1199 select %# 'aa=>1, cq=>l, b=>g, fg=>NULL';
1201 ---------------------------------
1202 {{b,g},{aa,1},{cq,l},{fg,NULL}}
1205 select * from skeys('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
1214 select * from skeys('""=>1');
1220 select * from skeys('');
1225 select * from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>f');
1234 select *, svals is null from svals('aa=>1 , b=>2, cq=>3'::hstore || 'cq=>l, b=>g, fg=>NULL');
1243 select * from svals('""=>1');
1249 select * from svals('');
1254 select * from each('aaa=>bq, b=>NULL, ""=>1 ');
1263 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
1269 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>NULL';
1275 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, g=>NULL';
1281 select 'a=>b, b=>1, c=>NULL'::hstore @> 'g=>NULL';
1287 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>c';
1293 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b';
1299 select 'a=>b, b=>1, c=>NULL'::hstore @> 'a=>b, c=>q';
1305 CREATE TABLE testhstore (h hstore);
1306 \copy testhstore from 'data/hstore.data'
1307 select count(*) from testhstore where h @> 'wait=>NULL';
1313 select count(*) from testhstore where h @> 'wait=>CC';
1319 select count(*) from testhstore where h @> 'wait=>CC, public=>t';
1325 select count(*) from testhstore where h ? 'public';
1331 select count(*) from testhstore where h ?| ARRAY['public','disabled'];
1337 select count(*) from testhstore where h ?& ARRAY['public','disabled'];
1343 create index hidx on testhstore using gist(h);
1344 set enable_seqscan=off;
1345 select count(*) from testhstore where h @> 'wait=>NULL';
1351 select count(*) from testhstore where h @> 'wait=>CC';
1357 select count(*) from testhstore where h @> 'wait=>CC, public=>t';
1363 select count(*) from testhstore where h ? 'public';
1369 select count(*) from testhstore where h ?| ARRAY['public','disabled'];
1375 select count(*) from testhstore where h ?& ARRAY['public','disabled'];
1382 create index hidx on testhstore using gist(h gist_hstore_ops(siglen=0));
1383 ERROR: value 0 out of bounds for option "siglen"
1384 DETAIL: Valid values are between "1" and "2024".
1385 create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2025));
1386 ERROR: value 2025 out of bounds for option "siglen"
1387 DETAIL: Valid values are between "1" and "2024".
1388 create index hidx on testhstore using gist(h gist_hstore_ops(siglen=2024));
1389 set enable_seqscan=off;
1390 select count(*) from testhstore where h @> 'wait=>NULL';
1396 select count(*) from testhstore where h @> 'wait=>CC';
1402 select count(*) from testhstore where h @> 'wait=>CC, public=>t';
1408 select count(*) from testhstore where h ? 'public';
1414 select count(*) from testhstore where h ?| ARRAY['public','disabled'];
1420 select count(*) from testhstore where h ?& ARRAY['public','disabled'];
1427 create index hidx on testhstore using gin (h);
1428 set enable_seqscan=off;
1429 select count(*) from testhstore where h @> 'wait=>NULL';
1435 select count(*) from testhstore where h @> 'wait=>CC';
1441 select count(*) from testhstore where h @> 'wait=>CC, public=>t';
1447 select count(*) from testhstore where h ? 'public';
1453 select count(*) from testhstore where h ?| ARRAY['public','disabled'];
1459 select count(*) from testhstore where h ?& ARRAY['public','disabled'];
1465 select count(*) from (select (each(h)).key from testhstore) as wow ;
1471 select key, count(*) from (select (each(h)).key from testhstore) as wow group by key order by count desc, key;
1499 select count(distinct h) from testhstore;
1505 set enable_hashagg = false;
1506 select count(*) from (select h from (select * from testhstore union all select * from testhstore) hs group by h) hs2;
1512 set enable_hashagg = true;
1513 set enable_sort = false;
1514 select count(*) from (select h from (select * from testhstore union all select * from testhstore) hs group by h) hs2;
1520 select distinct * from (values (hstore '' || ''),('')) v(h);
1526 set enable_sort = true;
1529 create index hidx on testhstore using btree (h);
1530 set enable_seqscan=off;
1531 select count(*) from testhstore where h #># 'p=>1';
1537 select count(*) from testhstore where h = 'pos=>98, line=>371, node=>CBA, indexed=>t';
1544 select hstore_to_json('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4');
1546 -------------------------------------------------------------------------------------------------
1547 {"b": "t", "c": null, "d": "12345", "e": "012345", "f": "1.234", "g": "2.345e+4", "a key": "1"}
1550 select cast( hstore '"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4' as json);
1552 -------------------------------------------------------------------------------------------------
1553 {"b": "t", "c": null, "d": "12345", "e": "012345", "f": "1.234", "g": "2.345e+4", "a key": "1"}
1556 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"');
1557 hstore_to_json_loose
1558 -------------------------------------------------------------------------------------------------------------
1559 {"b": true, "c": null, "d": 12345, "e": "012345", "f": 1.234, "g": 2.345e+4, "h": "2016-01-01", "a key": 1}
1562 select hstore_to_jsonb('"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4');
1564 -------------------------------------------------------------------------------------------------
1565 {"b": "t", "c": null, "d": "12345", "e": "012345", "f": "1.234", "g": "2.345e+4", "a key": "1"}
1568 select cast( hstore '"a key" =>1, b => t, c => null, d=> 12345, e => 012345, f=> 1.234, g=> 2.345e+4' as jsonb);
1570 -------------------------------------------------------------------------------------------------
1571 {"b": "t", "c": null, "d": "12345", "e": "012345", "f": "1.234", "g": "2.345e+4", "a key": "1"}
1574 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"');
1575 hstore_to_jsonb_loose
1576 ----------------------------------------------------------------------------------------------------------
1577 {"b": true, "c": null, "d": 12345, "e": "012345", "f": 1.234, "g": 23450, "h": "2016-01-01", "a key": 1}
1580 create table test_json_agg (f1 text, f2 hstore);
1581 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'),
1582 ('rec2','"a key" =>2, b => f, c => "null", d=> -12345, e => 012345.6, f=> -1.234, g=> 0.345e-4');
1583 select json_agg(q) from test_json_agg q;
1585 ----------------------------------------------------------------------------------------------------------------------------
1586 [{"f1":"rec1","f2":{"b": "t", "c": null, "d": "12345", "e": "012345", "f": "1.234", "g": "2.345e+4", "a key": "1"}}, +
1587 {"f1":"rec2","f2":{"b": "f", "c": "null", "d": "-12345", "e": "012345.6", "f": "-1.234", "g": "0.345e-4", "a key": "2"}}]
1590 select json_agg(q) from (select f1, hstore_to_json_loose(f2) as f2 from test_json_agg) q;
1592 ----------------------------------------------------------------------------------------------------------------------
1593 [{"f1":"rec1","f2":{"b": true, "c": null, "d": 12345, "e": "012345", "f": 1.234, "g": 2.345e+4, "a key": 1}}, +
1594 {"f1":"rec2","f2":{"b": false, "c": "null", "d": -12345, "e": "012345.6", "f": -1.234, "g": 0.345e-4, "a key": 2}}]
1597 -- Test subscripting
1598 insert into test_json_agg default values;
1599 select f2['d'], f2['x'] is null as x_isnull from test_json_agg;
1607 select f2['d']['e'] from test_json_agg; -- error
1608 ERROR: hstore allows only one subscript
1609 select f2['d':'e'] from test_json_agg; -- error
1610 ERROR: hstore allows only one subscript
1611 update test_json_agg set f2['d'] = f2['e'], f2['x'] = 'xyzzy';
1612 select f2 from test_json_agg;
1614 ---------------------------------------------------------------------------------------------------------------------
1615 "b"=>"t", "c"=>NULL, "d"=>"012345", "e"=>"012345", "f"=>"1.234", "g"=>"2.345e+4", "x"=>"xyzzy", "a key"=>"1"
1616 "b"=>"f", "c"=>"null", "d"=>"012345.6", "e"=>"012345.6", "f"=>"-1.234", "g"=>"0.345e-4", "x"=>"xyzzy", "a key"=>"2"
1617 "d"=>NULL, "x"=>"xyzzy"
1620 -- Test subscripting in plpgsql
1621 do $$ declare h hstore;
1622 begin h['a'] := 'b'; raise notice 'h = %, h[a] = %', h, h['a']; end $$;
1623 NOTICE: h = "a"=>"b", h[a] = b
1624 -- Check the hstore_hash() and hstore_hash_extended() function explicitly.
1625 SELECT v as value, hstore_hash(v)::bit(32) as standard,
1626 hstore_hash_extended(v, 0)::bit(32) as extended0,
1627 hstore_hash_extended(v, 1)::bit(32) as extended1
1628 FROM (VALUES (NULL::hstore), (''), ('"a key" =>1'), ('c => null'),
1629 ('e => 012345'), ('g => 2.345e+4')) x(v)
1630 WHERE hstore_hash(v)::bit(32) != hstore_hash_extended(v, 0)::bit(32)
1631 OR hstore_hash(v)::bit(32) = hstore_hash_extended(v, 1)::bit(32);
1632 value | standard | extended0 | extended1
1633 -------+----------+-----------+-----------