Home Explore Blog CI



postgresql

4th chunk of `doc/src/sgml/hstore.sgml`
5cd0aa142dd13a65bd5da8ef1dc1f93743415ebe4ee7ebf90000000100000fa1
 <returnvalue>anyelement</returnvalue>
       </para>
       <para>
        Replaces fields in the left operand (which must be a composite type)
        with matching values from <type>hstore</type>.
       </para>
       <para>
        <literal>ROW(1,3) #= 'f1=>11'::hstore</literal>
        <returnvalue>(11,3)</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <literal>%%</literal> <type>hstore</type>
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Converts <type>hstore</type> to an array of alternating keys and
        values.
       </para>
       <para>
        <literal>%% 'a=&gt;foo, b=&gt;bar'::hstore</literal>
        <returnvalue>{a,foo,b,bar}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <literal>%#</literal> <type>hstore</type>
        <returnvalue>text[]</returnvalue>
       </para>
       <para>
        Converts <type>hstore</type> to a two-dimensional key/value array.
       </para>
       <para>
        <literal>%# 'a=&gt;foo, b=&gt;bar'::hstore</literal>
        <returnvalue>{{a,foo},{b,bar}}</returnvalue>
       </para></entry>
      </row>
     </tbody>
    </tgroup>
  </table>

  <table id="hstore-func-table">
   <title><type>hstore</type> Functions</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function
       </para>
       <para>
        Description
       </para>
       <para>
        Example(s)
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>hstore</primary></indexterm>
        <function>hstore</function> ( <type>record</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Constructs an <type>hstore</type> from a record or row.
       </para>
       <para>
        <literal>hstore(ROW(1,2))</literal>
        <returnvalue>"f1"=&gt;"1", "f2"=&gt;"2"</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>hstore</function> ( <type>text[]</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Constructs an <type>hstore</type> from an array, which may be either
        a key/value array, or a two-dimensional array.
       </para>
       <para>
        <literal>hstore(ARRAY['a','1','b','2'])</literal>
        <returnvalue>"a"=&gt;"1", "b"=&gt;"2"</returnvalue>
       </para>
       <para>
        <literal>hstore(ARRAY[['c','3'],['d','4']])</literal>
        <returnvalue>"c"=&gt;"3", "d"=&gt;"4"</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>
        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>

Title: hstore Operators and Functions in PostgreSQL
Summary
This section details various operators and functions for the hstore data type in PostgreSQL. It covers operators for converting hstore to arrays (%% and %#), and functions for constructing hstore from different data types like records, arrays, and individual key-value pairs. The hstore() function is particularly versatile, able to create hstore values from records, arrays (including 2D arrays), separate key and value arrays, or single key-value pairs. The section also introduces the akeys() function, which appears to extract keys from an hstore. Each operation is explained with its syntax, return type, and illustrative examples, demonstrating the flexibility and power of hstore in data manipulation and storage.