Open In App

PostgreSQL – POSITION Function

Improve
Improve
Like Article
Like
Save
Share
Report

The PostgreSQL POSITION() function returns the location of a substring in a string.

Syntax: POSITION(substring in string)

Let’s analyze the above syntax:

  • The substring argument is the string that is to be located.
  • The string argument represents the string for which the substring is to be searched.
  • The POSITION() function returns the location of the searched substring in integer form that represents the location of the substring within the string. It returns zero (0) if no matching substring found.

Example 1:

The following statement returns the position of the ‘Tutorial’ in the string ‘GeeksForGeeks Tutorial’:

SELECT POSITION('Tutorial' IN 'GeeksForGeeks Tutorial');

Output:

Example 2:

The POSITION() function returns the location of the first instance of the substring in the strings shown in the below example:

SELECT POSITION('am' IN 'I am a geek');

Output:


Last Updated : 01 Feb, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads