Home Explore Blog CI



postgresql

5th chunk of `doc/src/sgml/hstore.sgml`
f0bc131255fe76cc42429b92761761ceac033733e5c1a5c40000000100000faa
 <type>text[]</type>, <type>text[]</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Constructs an <type>hstore</type> from separate key and value arrays.
       </para>
       <para>
        <literal>hstore(ARRAY['a','b'], ARRAY['1','2'])</literal>
        <returnvalue>"a"=&gt;"1", "b"=&gt;"2"</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>hstore</function> ( <type>text</type>, <type>text</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Makes a single-item <type>hstore</type>.
       </para>
       <para>
        <literal>hstore('a', 'b')</literal>
        <returnvalue>"a"=&gt;"b"</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>akeys</primary></indexterm>
        <function>akeys</function> ( <type>hstore</type> )
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s keys as an array.
       </para>
       <para>
        <literal>akeys('a=&gt;1,b=&gt;2')</literal>
        <returnvalue>{a,b}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>skeys</primary></indexterm>
        <function>skeys</function> ( <type>hstore</type> )
        <returnvalue>setof text</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s keys as a set.
       </para>
       <para>
        <literal>skeys('a=&gt;1,b=&gt;2')</literal>
        <returnvalue></returnvalue>
<programlisting>
a
b
</programlisting>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>avals</primary></indexterm>
        <function>avals</function> ( <type>hstore</type> )
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s values as an array.
       </para>
       <para>
        <literal>avals('a=&gt;1,b=&gt;2')</literal>
        <returnvalue>{1,2}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>svals</primary></indexterm>
        <function>svals</function> ( <type>hstore</type> )
        <returnvalue>setof text</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s values as a set.
       </para>
       <para>
        <literal>svals('a=&gt;1,b=&gt;2')</literal>
        <returnvalue></returnvalue>
<programlisting>
1
2
</programlisting>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>hstore_to_array</primary></indexterm>
        <function>hstore_to_array</function> ( <type>hstore</type> )
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s keys and values as an array of
        alternating keys and values.
       </para>
       <para>
        <literal>hstore_to_array('a=&gt;1,b=&gt;2')</literal>
        <returnvalue>{a,1,b,2}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>hstore_to_matrix</primary></indexterm>
        <function>hstore_to_matrix</function> ( <type>hstore</type> )
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Extracts an <type>hstore</type>'s keys and values as a two-dimensional
        array.
       </para>
       <para>
        <literal>hstore_to_matrix('a=&gt;1,b=&gt;2')</literal>
        <returnvalue>{{a,1},{b,2}}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para

Title: hstore Functions in PostgreSQL
Summary
This section describes various functions for manipulating hstore data type in PostgreSQL. It includes functions for constructing hstore from different data types, and for extracting data from hstore. Key functions include: hstore() for creating hstore from arrays or key-value pairs; akeys() and skeys() for extracting keys as an array or set; avals() and svals() for extracting values as an array or set; hstore_to_array() for converting hstore to an alternating key-value array; and hstore_to_matrix() for converting hstore to a two-dimensional array. Each function is explained with its syntax, return type, and examples, demonstrating the versatility of hstore in data manipulation and storage. These functions provide powerful tools for working with key-value pair data in PostgreSQL.