37

I am trying CHARINDEX in Postgresql. But it says:

function CHARINDEX() does not exist

If no such inbuilt function exists in postgresql, then is there any function that serves as an alternative to charindex?
If yes, What is the CHARINDEX (SQL SERVER) equivalent in POSTGRESQL ?

1

2 Answers 2

61

The equivalent function in postgresql is:

strpos(string, substring)

Or:

position(substring in string)

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

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

Sign up to request clarification or add additional context in comments.

Comments

2
  • In SQL Server CHARINDEX syntax is

    SELECT CHARINDEX(Substring, String)
    

    and example as like

    SELECT CHARINDEX('m','Zarm')
    

    this query returned 4.

  • Case of PostgreSQL syntax is

    strpos(string, substring)
    

    And example is

    SELECT strpos('Amal', 'l')
    

    this query returned 4.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.