Home Explore Blog CI



postgresql

7th chunk of `doc/src/sgml/hstore.sgml`
1170e7b75b61a21318c6b40ce3cafdb923a159e92a06b7c60000000100000fa6
 <returnvalue>json</returnvalue>
       </para>
       <para>
        Converts an <type>hstore</type> to a <type>json</type> value, but
        attempts to distinguish numerical and Boolean values so they are
        unquoted in the JSON.
       </para>
       <para>
        <literal>hstore_to_json_loose('"a key"=&gt;1, b=&gt;t, c=&gt;null, d=&gt;12345, e=&gt;012345, f=&gt;1.234, g=&gt;2.345e+4')</literal>
        <returnvalue>{"a key": 1, "b": true, "c": null, "d": 12345, "e": "012345", "f": 1.234, "g": 2.345e+4}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>hstore_to_jsonb_loose</primary></indexterm>
        <function>hstore_to_jsonb_loose</function> ( <type>hstore</type> )
        <returnvalue>jsonb</returnvalue>
       </para>
       <para>
        Converts an <type>hstore</type> to a <type>jsonb</type> value, but
        attempts to distinguish numerical and Boolean values so they are
        unquoted in the JSON.
       </para>
       <para>
        <literal>hstore_to_jsonb_loose('"a key"=&gt;1, b=&gt;t, c=&gt;null, d=&gt;12345, e=&gt;012345, f=&gt;1.234, g=&gt;2.345e+4')</literal>
        <returnvalue>{"a key": 1, "b": true, "c": null, "d": 12345, "e": "012345", "f": 1.234, "g": 2.345e+4}</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>slice</primary></indexterm>
        <function>slice</function> ( <type>hstore</type>, <type>text[]</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Extracts a subset of an <type>hstore</type> containing only the
        specified keys.
       </para>
       <para>
        <literal>slice('a=&gt;1,b=&gt;2,c=&gt;3'::hstore, ARRAY['b','c','x'])</literal>
        <returnvalue>"b"=&gt;"2", "c"=&gt;"3"</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>each</primary></indexterm>
        <function>each</function> ( <type>hstore</type> )
        <returnvalue>setof record</returnvalue>
        ( <parameter>key</parameter> <type>text</type>,
        <parameter>value</parameter> <type>text</type> )
       </para>
       <para>
        Extracts an <type>hstore</type>'s keys and values as a set of records.
       </para>
       <para>
        <literal>select * from each('a=&gt;1,b=&gt;2')</literal>
        <returnvalue></returnvalue>
<programlisting>
 key | value
-----+-------
 a   | 1
 b   | 2
</programlisting>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>exist</primary></indexterm>
        <function>exist</function> ( <type>hstore</type>, <type>text</type> )
        <returnvalue>boolean</returnvalue>
       </para>
       <para>
        Does <type>hstore</type> contain key?
       </para>
       <para>
        <literal>exist('a=&gt;1', 'a')</literal>
        <returnvalue>t</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>defined</primary></indexterm>
        <function>defined</function> ( <type>hstore</type>, <type>text</type> )
        <returnvalue>boolean</returnvalue>
       </para>
       <para>
        Does <type>hstore</type> contain a non-<literal>NULL</literal> value
        for key?
       </para>
       <para>
        <literal>defined('a=&gt;NULL', 'a')</literal>
        <returnvalue>f</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>delete</primary></indexterm>
        <function>delete</function> ( <type>hstore</type>, <type>text</type> )
        <returnvalue>hstore</returnvalue>
       </para>
       <para>
        Deletes

Title: hstore Manipulation Functions in PostgreSQL
Summary
This section describes various functions for manipulating the hstore data type in PostgreSQL. These include slice() for extracting a subset of an hstore, each() for converting an hstore into a set of records, exist() for checking if a key exists in an hstore, defined() for verifying if a key has a non-NULL value, and delete() for removing a key-value pair from an hstore. The functions provide different ways to interact with and modify hstore data, such as extracting specific keys, converting to other formats, checking for key existence, and removing entries. Each function is accompanied by an example demonstrating its usage and expected output, illustrating how these operations can be performed on hstore data structures in PostgreSQL.