Postgresql Position Function

PostgreSQL: position Function

In this PostgreSQL post explains how to use the PostgreSQL position function with syntax and examples.

Description

The PostgreSQL position function returns the location of a substring in a string.

Syntax

The syntax for the position function in PostgreSQL is:

position( substring in string )

Parameters or Arguments

substring

The substring to search for in string.

string

The string to search.

Note

  • The first position in string is 1.
  • If substring is not found in string, then the position function will return 0.

Applies To

The position function can be used in the following versions of PostgreSQL:

  • PostgreSQL 9.4, PostgreSQL 9.3, PostgreSQL 9.2, PostgreSQL 9.1, PostgreSQL 9.0, PostgreSQL 8.4

Example

Let's look at some PostgreSQL position function examples and explore how to use the position function in PostgreSQL.

For example:

postgres=# SELECT position('B' in 'AODBA.com');
 position
----------

        4
(1 row)

postgres=# SELECT position('Z' in 'AODBA.com');
 position
----------

        0
(1 row)