Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

PostgreSQL – POSITION Function

  • Last Updated : 01 Feb, 2021

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:

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!