diff --git a/contrib/hstore/expected/hstore.out b/contrib/hstore/expected/hstore.out index 34db7f571e..6a26bc1874 100644 --- a/contrib/hstore/expected/hstore.out +++ b/contrib/hstore/expected/hstore.out @@ -758,36 +758,6 @@ select pg_column_size('a=>g, b=>c'::hstore || ('b'=>'gf')) (1 row) -- => arrays -select ARRAY['a','b','asd'] => ARRAY['g','h','i']; - ?column? --------------------------------- - "a"=>"g", "b"=>"h", "asd"=>"i" -(1 row) - -select ARRAY['a','b','asd'] => ARRAY['g','h',NULL]; - ?column? ---------------------------------- - "a"=>"g", "b"=>"h", "asd"=>NULL -(1 row) - -select ARRAY['z','y','x'] => ARRAY['1','2','3']; - ?column? ------------------------------- - "x"=>"3", "y"=>"2", "z"=>"1" -(1 row) - -select ARRAY['aaa','bb','c','d'] => ARRAY[null::text,null,null,null]; - ?column? ------------------------------------------------ - "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL -(1 row) - -select ARRAY['aaa','bb','c','d'] => null; - ?column? ------------------------------------------------ - "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL -(1 row) - select hstore 'aa=>1, b=>2, c=>3' => ARRAY['g','h','i']; ?column? ---------- @@ -812,29 +782,6 @@ select hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b','aa']; "b"=>"2", "c"=>"3", "aa"=>"1" (1 row) -select quote_literal('{}'::text[] => '{}'::text[]); - quote_literal ---------------- - '' -(1 row) - -select quote_literal('{}'::text[] => null); - quote_literal ---------------- - '' -(1 row) - -select ARRAY['a'] => '{}'::text[]; -- error -ERROR: arrays must have same bounds -select '{}'::text[] => ARRAY['a']; -- error -ERROR: arrays must have same bounds -select pg_column_size(ARRAY['a','b','asd'] => ARRAY['g','h','i']) - = pg_column_size('a=>g, b=>h, asd=>i'::hstore); - ?column? ----------- - t -(1 row) - select pg_column_size(hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b']) = pg_column_size('b=>2, c=>3'::hstore); ?column? @@ -910,6 +857,60 @@ select hstore('[0:2][1:2]={{a,g},{b,h},{asd,i}}'::text[]); "a"=>"g", "b"=>"h", "asd"=>"i" (1 row) +-- pairs of arrays +select hstore(ARRAY['a','b','asd'], ARRAY['g','h','i']); + hstore +-------------------------------- + "a"=>"g", "b"=>"h", "asd"=>"i" +(1 row) + +select hstore(ARRAY['a','b','asd'], ARRAY['g','h',NULL]); + hstore +--------------------------------- + "a"=>"g", "b"=>"h", "asd"=>NULL +(1 row) + +select hstore(ARRAY['z','y','x'], ARRAY['1','2','3']); + hstore +------------------------------ + "x"=>"3", "y"=>"2", "z"=>"1" +(1 row) + +select hstore(ARRAY['aaa','bb','c','d'], ARRAY[null::text,null,null,null]); + hstore +----------------------------------------------- + "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL +(1 row) + +select hstore(ARRAY['aaa','bb','c','d'], null); + hstore +----------------------------------------------- + "c"=>NULL, "d"=>NULL, "bb"=>NULL, "aaa"=>NULL +(1 row) + +select quote_literal(hstore('{}'::text[], '{}'::text[])); + quote_literal +--------------- + '' +(1 row) + +select quote_literal(hstore('{}'::text[], null)); + quote_literal +--------------- + '' +(1 row) + +select hstore(ARRAY['a'], '{}'::text[]); -- error +ERROR: arrays must have same bounds +select hstore('{}'::text[], ARRAY['a']); -- error +ERROR: arrays must have same bounds +select pg_column_size(hstore(ARRAY['a','b','asd'], ARRAY['g','h','i'])) + = pg_column_size('a=>g, b=>h, asd=>i'::hstore); + ?column? +---------- + t +(1 row) + -- records select hstore(v) from (values (1, 'foo', 1.2, 3::float8)) v(a,b,c,d); hstore diff --git a/contrib/hstore/hstore.sql.in b/contrib/hstore/hstore.sql.in index 75c4367ccc..b04d32a22d 100644 --- a/contrib/hstore/hstore.sql.in +++ b/contrib/hstore/hstore.sql.in @@ -1,4 +1,4 @@ -/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.12 2009/09/30 19:50:22 tgl Exp $ */ +/* $PostgreSQL: pgsql/contrib/hstore/hstore.sql.in,v 1.13 2010/06/15 19:48:30 rhaas Exp $ */ -- Adjust this setting to control where the objects get created. SET search_path = public; @@ -238,12 +238,6 @@ RETURNS hstore AS 'MODULE_PATHNAME', 'hstore_from_arrays' LANGUAGE C IMMUTABLE; -- not STRICT; allows (keys,null) -CREATE OPERATOR => ( - LEFTARG = text[], - RIGHTARG = text[], - PROCEDURE = hstore -); - CREATE FUNCTION hstore(text[]) RETURNS hstore AS 'MODULE_PATHNAME', 'hstore_from_array' diff --git a/contrib/hstore/sql/hstore.sql b/contrib/hstore/sql/hstore.sql index a88ff1dab9..190d7a2afa 100644 --- a/contrib/hstore/sql/hstore.sql +++ b/contrib/hstore/sql/hstore.sql @@ -172,21 +172,10 @@ select pg_column_size('a=>g, b=>c'::hstore || ('b'=>'gf')) = pg_column_size('a=>g, b=>gf'::hstore); -- => arrays -select ARRAY['a','b','asd'] => ARRAY['g','h','i']; -select ARRAY['a','b','asd'] => ARRAY['g','h',NULL]; -select ARRAY['z','y','x'] => ARRAY['1','2','3']; -select ARRAY['aaa','bb','c','d'] => ARRAY[null::text,null,null,null]; -select ARRAY['aaa','bb','c','d'] => null; select hstore 'aa=>1, b=>2, c=>3' => ARRAY['g','h','i']; select hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b']; select hstore 'aa=>1, b=>2, c=>3' => ARRAY['aa','b']; select hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b','aa']; -select quote_literal('{}'::text[] => '{}'::text[]); -select quote_literal('{}'::text[] => null); -select ARRAY['a'] => '{}'::text[]; -- error -select '{}'::text[] => ARRAY['a']; -- error -select pg_column_size(ARRAY['a','b','asd'] => ARRAY['g','h','i']) - = pg_column_size('a=>g, b=>h, asd=>i'::hstore); select pg_column_size(hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b']) = pg_column_size('b=>2, c=>3'::hstore); select pg_column_size(hstore 'aa=>1, b=>2, c=>3' => ARRAY['c','b','aa']) @@ -208,6 +197,19 @@ select hstore(ARRAY[[['a','g'],['b','h'],['asd','i']]]); select hstore('[0:5]={a,g,b,h,asd,i}'::text[]); select hstore('[0:2][1:2]={{a,g},{b,h},{asd,i}}'::text[]); +-- pairs of arrays +select hstore(ARRAY['a','b','asd'], ARRAY['g','h','i']); +select hstore(ARRAY['a','b','asd'], ARRAY['g','h',NULL]); +select hstore(ARRAY['z','y','x'], ARRAY['1','2','3']); +select hstore(ARRAY['aaa','bb','c','d'], ARRAY[null::text,null,null,null]); +select hstore(ARRAY['aaa','bb','c','d'], null); +select quote_literal(hstore('{}'::text[], '{}'::text[])); +select quote_literal(hstore('{}'::text[], null)); +select hstore(ARRAY['a'], '{}'::text[]); -- error +select hstore('{}'::text[], ARRAY['a']); -- error +select pg_column_size(hstore(ARRAY['a','b','asd'], ARRAY['g','h','i'])) + = pg_column_size('a=>g, b=>h, asd=>i'::hstore); + -- records select hstore(v) from (values (1, 'foo', 1.2, 3::float8)) v(a,b,c,d); create domain hstestdom1 as integer not null default 0; diff --git a/doc/src/sgml/hstore.sgml b/doc/src/sgml/hstore.sgml index f9110616f7..9dac2b3ec4 100644 --- a/doc/src/sgml/hstore.sgml +++ b/doc/src/sgml/hstore.sgml @@ -1,4 +1,4 @@ - + hstore @@ -120,13 +120,6 @@ "a"=>"b" - - text[] => text[] - construct an hstore from separate key and value arrays - ARRAY['a','b'] => ARRAY['1','2'] - "a"=>"1","b"=>"2" - - hstore => text[] extract a subset of an hstore @@ -264,6 +257,14 @@ a=>1, b=>2, c=>3, d=>4 + + hstore(text[], text[]) + hstore + construct an hstore from separate key and value arrays + hstore(ARRAY['a','b'], ARRAY['1','2']) + "a"=>"1","b"=>"2" + + akeys(hstore) text[]