(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?
----------
"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?
"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
-/* $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;
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'
= 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'])
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;
-<!-- $PostgreSQL: pgsql/doc/src/sgml/hstore.sgml,v 1.8 2010/02/27 04:29:44 tgl Exp $ -->
+<!-- $PostgreSQL: pgsql/doc/src/sgml/hstore.sgml,v 1.9 2010/06/15 19:48:30 rhaas Exp $ -->
<sect1 id="hstore">
<title>hstore</title>
<entry><literal>"a"=>"b"</literal></entry>
</row>
- <row>
- <entry><type>text[]</> <literal>=></> <type>text[]</></entry>
- <entry>construct an <type>hstore</> from separate key and value arrays</entry>
- <entry><literal>ARRAY['a','b'] => ARRAY['1','2']</literal></entry>
- <entry><literal>"a"=>"1","b"=>"2"</literal></entry>
- </row>
-
<row>
<entry><type>hstore</> <literal>=></> <type>text[]</></entry>
<entry>extract a subset of an <type>hstore</></entry>
<entry><literal>a=>1, b=>2, c=>3, d=>4</literal></entry>
</row>
+ <row>
+ <entry><function>hstore(text[], text[])</function></entry>
+ <entry><type>hstore</type></entry>
+ <entry>construct an <type>hstore</> from separate key and value arrays</entry>
+ <entry><literal>hstore(ARRAY['a','b'], ARRAY['1','2'])</literal></entry>
+ <entry><literal>"a"=>"1","b"=>"2"</literal></entry>
+ </row>
+
<row>
<entry><function>akeys(hstore)</function></entry>
<entry><type>text[]</type></entry>