totn PostgreSQL Functions

PostgreSQL: strpos Function

This PostgreSQL tutorial explains how to use the PostgreSQL strpos function with syntax and examples.

Description

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

Syntax

The syntax for the strpos function in PostgreSQL is:

strpos( string, substring )

Parameters or Arguments

string
The string to search.
substring
The substring to search for in string.

Note

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

Applies To

The strpos 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 strpos function examples and explore how to use the strpos function in PostgreSQL.

For example:

postgres=# SELECT strpos('Tech on the net', 'T');
 strpos
--------
      1
(1 row)

postgres=# SELECT strpos('Tech on the net', 't');
 strpos
--------
      9
(1 row)

postgres=# SELECT strpos('techonthenet.com', 'h');
 strpos
--------
      4
(1 row)

postgres=# SELECT strpos('techonthenet.com', 'Z');
 strpos
--------
      0
(1 row)