Top
Symfoware Server V12.1.0 Application Development Guide
FUJITSU Software

9.4.2 SUBSTR

Features

Extracts part of a character string.

Specification format

General rules

Note

  • There are two types of SUBSTR. One that behaves as described above, and one that behaves the same as SUBSTRING. The search_path needs to be modified for it to behave the same as the specification described above.

  • It is recommended to set search_path in postgresql.conf. In this case, it will be effective for each instance. Refer to "9.2.1 Notes on SUBSTR" for information on how to configure postgresql.conf.

  • The configuration of search_path can be done at the user level or at the database level. Setting examples are shown below.

    • Example of setting at the user level

      This can be set by executing an SQL command. "user1" will be used as the username in this example.

      ALTER USER user1 SET search_path = "$user",public,oracle,pg_catalog;
    • Example of setting at the database level

      This can be set by executing an SQL command. "db1" will be used as the database name in this example.

      ALTER DATABASE db1 SET search_path = "$user",public,oracle,pg_catalog;

      You must specify "oracle" in front of "pg_catalog".

  • If the change has not been implemented, SUBSTR is the same as SUBSTRING.

See

Refer to "SQL Commands" under "Reference" in the PostgreSQL Documentation for information on ALTER USER and ALTER DATABASE.

Information

The general rules for SUBSTRING are as follows:

  • The starting position will be from the beginning of the character value expression, whether the starting position is positive, 0, or negative.

  • When string length is not specified, all characters until the end of the character value expression are returned.

  • An empty string is returned if the returned string is 0 or less or if the specified string length is less than 1.

See

Refer to "String Functions and Operators" under "The SQL Language" in the PostgreSQL Documentation for information on SUBSTRING.

Example

In the following example, part of the string "ABCDEFG" is extracted:

SELECT SUBSTR('ABCDEFG',3,4) "Substring" FROM DUAL;
 
 Substring
-----------
 CDEF
(1 row)

SELECT SUBSTR('ABCDEFG',-5,4) "Substring" FROM DUAL;

 Substring
-----------
 CDEF
(1 row)