Open In App

PostgreSQL – POSITION Function

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

Syntax: POSITION(substring in string)

Let’s analyze the above syntax:



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:

Article Tags :