Home Explore Blog CI



postgresql

6th chunk of `doc/src/sgml/ltree.sgml`
8bf910a5095c10fa54b0e0d06eebb974bb7c69410375d14b0000000100000fa0
 <returnvalue>ltree</returnvalue>
       </para>
       <para>
        Returns first array entry that matches <type>lquery</type>,
        or <literal>NULL</literal> if none.
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <type>ltree[]</type> <literal>?@</literal> <type>ltxtquery</type>
        <returnvalue>ltree</returnvalue>
       </para>
       <para>
        Returns first array entry that matches <type>ltxtquery</type>,
        or <literal>NULL</literal> if none.
       </para></entry>
      </row>
     </tbody>
    </tgroup>
  </table>

  <para>
   The operators <literal>&lt;@</literal>, <literal>@&gt;</literal>,
   <literal>@</literal> and <literal>~</literal> have analogues
   <literal>^&lt;@</literal>, <literal>^@&gt;</literal>, <literal>^@</literal>,
   <literal>^~</literal>, which are the same except they do not use
   indexes.  These are useful only for testing purposes.
  </para>

  <para>
   The available functions are shown in <xref linkend="ltree-func-table"/>.
  </para>

  <table id="ltree-func-table">
   <title><type>ltree</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>subltree</primary></indexterm>
        <function>subltree</function> ( <type>ltree</type>, <parameter>start</parameter> <type>integer</type>, <parameter>end</parameter> <type>integer</type> )
        <returnvalue>ltree</returnvalue>
       </para>
       <para>
        Returns subpath of <type>ltree</type> from
        position <parameter>start</parameter> to
        position <parameter>end</parameter>-1 (counting from 0).
       </para>
       <para>
        <literal>subltree('Top.Child1.Child2', 1, 2)</literal>
        <returnvalue>Child1</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>subpath</primary></indexterm>
        <function>subpath</function> ( <type>ltree</type>, <parameter>offset</parameter> <type>integer</type>, <parameter>len</parameter> <type>integer</type> )
        <returnvalue>ltree</returnvalue>
       </para>
       <para>
        Returns subpath of <type>ltree</type> starting at
        position <parameter>offset</parameter>, with
        length <parameter>len</parameter>.  If <parameter>offset</parameter>
        is negative, subpath starts that far from the end of the path.
        If <parameter>len</parameter> is negative, leaves that many labels off
        the end of the path.
       </para>
       <para>
        <literal>subpath('Top.Child1.Child2', 0, 2)</literal>
        <returnvalue>Top.Child1</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <function>subpath</function> ( <type>ltree</type>, <parameter>offset</parameter> <type>integer</type> )
        <returnvalue>ltree</returnvalue>
       </para>
       <para>
        Returns subpath of <type>ltree</type> starting at
        position <parameter>offset</parameter>, extending to end of path.
        If <parameter>offset</parameter> is negative, subpath starts that far
        from the end of the path.
       </para>
       <para>
        <literal>subpath('Top.Child1.Child2', 1)</literal>
        <returnvalue>Child1.Child2</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm><primary>nlevel</primary></indexterm>
        <function>nlevel</function> ( <type>ltree</type> )
        <returnvalue>integer</returnvalue>
       </para>
   

Title: ltree Functions
Summary
The ltree data type supports various functions for manipulating and querying hierarchical data, including subltree, subpath, and nlevel, which allow for extracting subpaths, getting the number of levels in a path, and more, with examples provided for each function.