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

会有一股神秘感。 提交于 2019-12-23 06:54:13

问题


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:


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



来源:https://stackoverflow.com/questions/30778444/what-is-the-charindex-sql-server-equivalent-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!