What is the equivalent of CHARINDEX (SQL SERVER) in POSTGRESQL?

I am trying to CHARINDEX in Postgresql. But it says:

 function CHARINDEX() does not exist 

If in postgresql such a built-in function does not exist, is there any function that serves as an alternative to charindex?
If so, what is the equivalent of CHARINDEX (SQL SERVER) in POSTGRESQL?

+14
source share
1 answer

Equivalent function in postgresql:

 strpos(string, substring) 

Or:

 position(substring in string) 

They are equivalent, just with a different order in the parameters.
If you also need the start_location parameter, you need to pass the substring to strpos.

You can find them at: https://www.postgresql.org/docs/current/functions-string.html

+24
source

All Articles