Home Explore Blog CI



postgresql

34th chunk of `doc/src/sgml/func.sgml`
c76bbf3d026fd837c6e994224819a9fe2e670d57701508bf0000000100000fa0
 listed in <xref linkend="functions-string-other"/>.  (Some of
    these are used internally to implement
    the <acronym>SQL</acronym>-standard string functions listed in
    <xref linkend="functions-string-sql"/>.)
    There are also pattern-matching operators, which are described in
    <xref linkend="functions-matching"/>, and operators for full-text
    search, which are described in <xref linkend="textsearch"/>.
   </para>

   <table id="functions-string-other">
    <title>Other String Functions and Operators</title>
    <tgroup cols="1">
     <thead>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        Function/Operator
       </para>
       <para>
        Description
       </para>
       <para>
        Example(s)
       </para></entry>
      </row>
     </thead>

     <tbody>
      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>character string</primary>
         <secondary>prefix test</secondary>
        </indexterm>
        <type>text</type> <literal>^@</literal> <type>text</type>
        <returnvalue>boolean</returnvalue>
       </para>
       <para>
        Returns true if the first string starts with the second string
        (equivalent to the <function>starts_with()</function> function).
       </para>
       <para>
        <literal>'alphabet' ^@ 'alph'</literal>
        <returnvalue>t</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>ascii</primary>
        </indexterm>
        <function>ascii</function> ( <type>text</type> )
        <returnvalue>integer</returnvalue>
       </para>
       <para>
        Returns the numeric code of the first character of the argument.
        In <acronym>UTF8</acronym> encoding, returns the Unicode code point
        of the character.  In other multibyte encodings, the argument must
        be an <acronym>ASCII</acronym> character.
       </para>
       <para>
        <literal>ascii('x')</literal>
        <returnvalue>120</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>chr</primary>
        </indexterm>
        <function>chr</function> ( <type>integer</type> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Returns the character with the given code. In <acronym>UTF8</acronym>
        encoding the argument is treated as a Unicode code point. In other
        multibyte encodings the argument must designate
        an <acronym>ASCII</acronym> character.  <literal>chr(0)</literal> is
        disallowed because text data types cannot store that character.
      </para>
      <para>
        <literal>chr(65)</literal>
        <returnvalue>A</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>concat</primary>
        </indexterm>
        <function>concat</function> ( <parameter>val1</parameter> <type>"any"</type>
         <optional>, <parameter>val2</parameter> <type>"any"</type> <optional>, ...</optional> </optional> )
        <returnvalue>text</returnvalue>
       </para>
       <para>
        Concatenates the text representations of all the arguments.
        NULL arguments are ignored.
       </para>
       <para>
        <literal>concat('abcde', 2, NULL, 22)</literal>
        <returnvalue>abcde222</returnvalue>
       </para></entry>
      </row>

      <row>
       <entry role="func_table_entry"><para role="func_signature">
        <indexterm>
         <primary>concat_ws</primary>
        </indexterm>
        <function>concat_ws</function> ( <parameter>sep</parameter> <type>text</type>,
        <parameter>val1</parameter> <type>"any"</type>
        <optional>, <parameter>val2</parameter> <type>"any"</type>

Title: Other String Functions and Operators in PostgreSQL: Prefix Test, ASCII, CHR, CONCAT, CONCAT_WS
Summary
This section details other string functions and operators in PostgreSQL, including the prefix test operator (`^@`), the `ascii` function (returns the numeric code of the first character), the `chr` function (returns the character with the given code), the `concat` function (concatenates text representations of arguments, ignoring NULLs), and the `concat_ws` function (concatenates with a separator).